利用shelve模块,保存python程序中的变量到二进制shelf文件中。
将变量写进文件中,shelfFile就像一个字典
import shelve
shelfFile = shelve.open(filePath)
color = ['blue','red','green']
shelfFile['color'] = color
shelfFile.close()
需要用到shelfFile中值的时候,打开文件,以字典形式调用就可以了
利用shelve模块,保存python程序中的变量到二进制shelf文件中。
将变量写进文件中,shelfFile就像一个字典
import shelve
shelfFile = shelve.open(filePath)
color = ['blue','red','green']
shelfFile['color'] = color
shelfFile.close()
需要用到shelfFile中值的时候,打开文件,以字典形式调用就可以了
本文标题:Python shelve模块保存变量
本文链接:https://www.haomeiwen.com/subject/xsxsmftx.html
网友评论