码迷,mamicode.com
首页 > 编程语言 > 详细

python 模块之-shelve

时间:2018-04-29 01:26:34      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:模块   website   shelve   字典   get   print   pre   支持   com   

shelve模块比pickle模块简单,只有一个open函数,返回类似字典的对象,可读可写;key必须为字符串,而值可以是python所支持的数据类型

import shelve
 
f = shelve.open(r‘shelve.txt‘)
 
# f[‘stu1_info‘]={‘name‘:‘alex‘,‘age‘:‘18‘}
# f[‘stu2_info‘]={‘name‘:‘alvin‘,‘age‘:‘20‘}
# f[‘school_info‘]={‘website‘:‘oldboyedu.com‘,‘city‘:‘beijing‘}
#
#
# f.close()
 
print(f.get(‘stu_info‘)[‘age‘])

  

python 模块之-shelve

标签:模块   website   shelve   字典   get   print   pre   支持   com   

原文地址:https://www.cnblogs.com/kuku0223/p/8969999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!