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基础教程
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)