SHELVE模块

# import shelve
#
# f = shelve.open('shelve_text')
# #存
# f['info'] = {'name':'xuxu'}
# f['shop'] = {'price':'100'}
#
# #取
# dat = f.get('info')
# print(dat)

d = {'name':'xuxu','age':'25'}

print(d['name'])
print(d.get('name'))
print(d.get('sex'))#None
print(d.get('sex','male'))#没有默认值male,有的话返回正确结果
print(d.get('name','male'))#xuxu
posted @ 2017-12-21 16:08  无敌帅帅头  阅读(100)  评论(0编辑  收藏  举报