Python 持久化管理之 Pickle/ZODB
1.对象持久化
2. Pickle模块
In [3]: import cPickle as pickle In [4]: a1=['apple','banana','orange'] In [5]: b1={'one':1,'two':2,'three':3} In [6]: f=open('temp.pkl','wb') In [7]: pickle.dump(a1,f) In [8]: pickle.dump(b1,f) In [9]: f.close() In [10]: f2 = file('temp.pkl','rb') In [11]: recover1 = pickle.load(f2) In [12]: print recover1 ['apple', 'banana', 'orange'] In [13]: recover2 = pickle.load(f2) In [14]: print recover2 {'one': 1, 'three': 3, 'two': 2} In [15]: f2.close()
相关文章