导语:
本文主要介绍了关于python使用shelve保存变量的相关知识,希望可以帮到处于编程学习途中的小伙伴
1、使用shelve模块,可以将Python中的变量保存到一个二进制的shelve文件中。
这样,程序就可以从硬盘中恢复变量的数据。
import shelve
shelfFile = shelve.open('mydata')
cats = ['Zonphie','Pooka','Simon']
shelfFile['cats'] = cats
shelfFile.close()
2. shelf value不需要以读模式或者写模式打开,因为打开后就可以读写了。
shelfFile = shelve.open('mydata')
type(shelfFile)
shelve.DbfilenameShelf
shelfFile['cats']
shelfFile.close()
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
本文为原创文章,版权归知行编程网所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 如何在python中获取函数的返回值09/06
- ♥ 如何在python中连接到telnet11/30
- ♥ python如何清空文件内容08/25
- ♥ python异常模块的整理11/05
- ♥ python如何打印字符串的长度10/13
- ♥ 如何解决python安装失败的原因08/22
内容反馈