shelve:模块
import shelve
shelve.open('db.shl')
f['su1']=['name':'bn','age':34]   #把su1当做key,后面的当做值,然后放进db.sh1文件里面
f['su2']=['name':'bn2','age'45]  
print(f['su1']['name'])
f.close()

xml:模块
from  xml.etree import ElementTree
tree=ElementTree.parse('a.xml')  #xml文件

root=tree.getroot()   #拿到根
print(root.tag)   #标签的名字
print(root.attrib)  #看属性
print(root.text)    #文本

#三种查找方式
#1.从子节点中找
print(root.find())
root.findall()

#2.从整树型结构中查找
root.iter('rank')  #全篇文件找
print(list(root.iter()))

#遍历文档树
for country in root:
    print(country.attrib['name'])
    for item in country:
            print(item.tag,item.attrib,item.text)

#找文件中的时间
for year in root.iter('year'):
    print(year.tag,year.attrib,year.text)

#修改
for year in root.iter('year'):
    year.set('update',"yes")
    year.text=str((year.text)+1)

tree.write('a.xml')

#添加节点
for country in root:
    obj=ElementTree.Element()   #egon is good
    obj.attrib={'name':'egon','age':'18'}
    obj.text='egon is good'
    country.append(obj)
tree.write('a.xml')