python3.2 数据存储pickle模块的使用方法详解,python3.2pickle,这是一篇关于python


这是一篇关于python持久性管理python pickle模块详细介绍的文章,文中讲了python中的pickle如何使用原理的代码应用实例。python3.2中的pickle模块简单的理解是为了序列化/反序列化一个对象的,作用是可以把一个对象持久化存储。

pickle模块对数据的简单存储处理的方法

import pickleshoplistfile = 'shoplist.data'# the name of the file where we will store the objectshoplist = ['apple', 'mango', 'carrot']# Write to the filef = open(shoplistfile, 'wb')#help(f)#www.iplaypy.compickle.dump(shoplist, f) # dump the object to a filef.close()del shoplist # remove the shoplist# Read back from the storagef = open(shoplistfile, 'rb')storedlist = pickle.load(f)print(storedlist)

编橙之家文章,

评论关闭