我试图将列表存储在一个平面文件中,由于某种原因我没有看到正在创建的文件..在 c:\python27\basics\db.txt
这是我的代码:
make_db_pickle.py
from Basics import data
import pickle
db = data.people
dbfilename = 'c:\python27\Basics\db.txt'
try:
dbfile = open('dbfilename','wb')
except IOError as (errno,strerror):
print "I/O error({0}): {1}".format(errno, strerror)
except ValueError:
print "Could not convert data to an integer."
except:
print "Unexpected Error", sys.exc_info() [0]
pickle.dump(db,dbfile)
dbfile.close()
数据.py
bob={'name':'bobs mith','age':42,'salary':5000,'job':'software'}
sue={'name':'sue more','age':30,'salary':3000,'job':'hardware'}
people={}
people['bob'] = bob
people['sue'] = sue