面向对象

python 并不会自动调用超类的构造函数!需要编程者自己显示的调用

对象持久化

dump & load

#!/usr/bin/python
# Filename: pickling.py
import cPickle as p
#import pickle as p

shoplistfile = 'shoplist.data' # the name of the file where we will store the objec
shoplist = ['apple', 'mango', 'carrot']
# Write to the file
f = open(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 = open(shoplistfile, 'r')
storedlist = p.load(f)
print storedlist
f.close()

参考资料

  1. a byte of python