shelve模塊比pickle模塊簡單尺碰,只有一個open函數(shù),返回類似字典的對象,可讀可寫;key必須為字符串牌捷,而值可以是python所支持的數(shù)據(jù)類型
import shelve
f=shelve.open(r'sheve.txt')
# f['stu1_info']={'name':'egon','age':18,'hobby':['piao','smoking','drinking']}
# f['stu2_info']={'name':'gangdan','age':53}
# f['school_info']={'website':'http://www.pypy.org','city':'beijing'}
print(f['stu1_info']['hobby'])
f.close()