Python shelve模块保存变量

利用shelve模块,保存python程序中的变量到二进制shelf文件中。

将变量写进文件中,shelfFile就像一个字典
import shelve
shelfFile = shelve.open(filePath)
color = ['blue','red','green']
shelfFile['color'] = color
shelfFile.close()

需要用到shelfFile中值的时候,打开文件,以字典形式调用就可以了

你可能感兴趣的:(Python shelve模块保存变量)