720全景网站怎么做,某商贸网站建设方案,财经类 直播类网站开发,泰兴网站建设公司8#xff09;json pickle 用于序列化的两个模块 json#xff0c;用于处理字符串和python数据类型间进行转换 pickle#xff0c;用于python特有的类型和python的数据类型间进行站换 Json模块提供了四个功能#xff1a;dumps、dump、loads、load pickle模块提供了四个功…8json pickle 用于序列化的两个模块 json用于处理字符串和python数据类型间进行转换 pickle用于python特有的类型和python的数据类型间进行站换 Json模块提供了四个功能dumps、dump、loads、load pickle模块提供了四个功能dumps、dump、loads、load import pickle data {k1:1234,k2:hello ykyk} p_str pickle.dumps(data) print(p_str) b\x80\x03}q\x00(X\x02\x00\x00\x00k1q\x01M\xd2\x04X\x02\x00\x00\x00k2q\x02X\n\x00\x00\x00hello ykykq\x03u. import pickle data {k1:12345,k2:hello} p_str pickle.dumps(data) with open(/test/practise/tina.pk,w) as fp: pickle.dump(data,fp) import json data {k1:12345,k2:hello} p_str json.dumps(data) with open(/test/practise/tina,w) as fp: json.dump(data,fp) 9shelve模块 import shelve d shelve.open(shelve_test) #打开一个文件 class Test(object): def __init__(self,n): self.n n t Test(123) t2 Test(123334) name [alex,rain,test] d[test] name #持久化列表 d[t1] t #持久化类 d[t2] t2 d.close() 10xml处理模块 xml是实现不同语言或者程序之间进行数据交换的协议。 样例文件 ?xml version1.0? data country nameLiechtenstein rank updatedyes2/rank year2008/year gdppc141100/gdppc neighbor nameAustria directionE/ neighbor nameSwitzerland directionW/ /country country nameSingapore rank updatedyes5/rank year2011/year gdppc59900/gdppc neighbor nameMalaysia directionN/ /country country namePanama rank updatedyes69/rank year2011/year gdppc13600/gdppc neighbor nameCosta Rica directionW/ neighbor nameColombia directionE/ /country /data 使用方法 import xml.etree.ElementTree as ET tree ET.parse(xmltest.xml) root tree.getroot() print(root.tag) #遍历xml文档 for child in root: print(child.tag, child.attrib) for i in child: print(i.tag,i.text) #只遍历year 节点 for node in root.iter(year): print(node.tag,node.text) 修改 删除 import xml.etree.ElementTree as ET tree ET.parse(xmltest.xml) root tree.getroot() #修改 for node in root.iter(year): new_year int(node.text) 1 node.text str(new_year) node.set(updated,yes) tree.write(xmltest.xml) #删除node for country in root.findall(country): rank int(country.find(rank).text) if rank 50: root.remove(country) tree.write(output.xml) 11) re正则表达式模块 . 默认匹配除\n之外的任意一个字符若指定flag DOTALL,则匹配任意字符包括换行 ^ 匹配字符开头若指定flags MULTILINE,这种也可以匹配上(r^a,\nabc\neee,flagsre.MULTILINE) $ 匹配字符结尾或e.search(foo$,bfoo\nsdfsf,flagsre.MULTILINE).group()也可以 * 匹配*号前的字符0次或多次re.findall(ab*,cabb3abcbbac) 结果为[abb, ab, a] 匹配前一个字符1次或多次re.findall(ab,abcdabbbba) 结果[ab, abb] ? 匹配前一个字符1次或0次 {m} 匹配前一个字符m次 {n,m} 匹配前一个字符n到m次re.findall(ab{1,3},abb abc abbcbbb) 结果abb, ab, abb] | 匹配|左或|右的字符re.search(abc|ABC,ABCBabcCD).group() 结果ABC (...) 分组匹配re.search((abc){2}a(123|456)c, abcabca456c).group() 结果 abcabca456c \A 只从字符开头匹配re.search(\Aabc,alexabc) 是匹配不到的 \Z 匹配字符结尾同$ \d 匹配数字0-9 \D 匹配非数字 \w 匹配[A-Za-z0-9] \W 匹配非[A-Za-z0-9] s 匹配空白字符、\t、\n、\r , re.search(\s,ab\tc1\n3).group() 结果 \t (?Pname...) 分组匹配 re.search((?Pprovince[0-9]{4})(?Pcity[0-9]{2})(?Pbirthday[0-9]{4}),210624199305100044).groupdict(city) {province: 2106, city: 24, birthday: 1993} 常用命令re.match 从头开始匹配re.search 匹配包含re.findall 把所有匹配到的字符放到以列表中的元素返回re.splitall 以匹配到的字符当做列表分隔符re.sub 匹配字符并替换正则表达式定义正则表达式是一些用来匹配和处理文本的字符串正则表达式语言并不是一种完备的程序设计语言他甚至算不上是一种能够直接安装并运行的程序更准确的说正则表达式语言是内置于其他语言或软件产品里的“迷你”语言转载于:https://www.cnblogs.com/ykyk1229/p/8572858.html