首页IT科技python用变量data保存字符串(python使用shelve保存变量)

python用变量data保存字符串(python使用shelve保存变量)

时间2025-05-02 16:49:49分类IT科技浏览3338
导读:1、用shelve模块,可以将Python中的变量保存到二进制的shelf文件中。...

1            、用shelve模块        ,可以将Python中的变量保存到二进制的shelf文件中        。

这样                 ,程序就可以从硬盘中恢复变量的数据                 。

importshelve shelfFile=shelve.open(mydata) cats=[Zonphie,Pooka,Simon] shelfFile[cats]=cats shelfFile.close()

2              、shelf值不必用读模式或写模式打开      ,因为打开后      ,既能读又能写      。

shelfFile=shelve.open(mydata) type(shelfFile) shelve.DbfilenameShelf shelfFile[cats] shelfFile.close()

以上就是python使用shelve保存变量的方法                ,希望对大家有所帮助      。更多Python学习指路:Python基础教程

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
python语言中and(python and用法) 通山县在哪里(通山县属于哪里?)