pickling.py

来自「python简明教程源代码」· Python 代码 · 共 23 行

PY
23
字号
# -*- coding: cp936 -*-
# Filename: pickling.py

import cPickle as p
# import pickle as p

shoplistfile = 'shoplist.data'
# the name of the file where we will stor the object

shoplist = ['apple', 'mango', 'carrot']

# Write to the file
f = file(shoplistfile, 'w')
p.dump(shoplist,f) # dump the object to a file
f.close()

del shoplist # remove the shoplist

# Read back from the storage
f = file(shoplistfile)
storedlist = p.load(f)
print storedlist

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?