请教python3.6下的pickle.dump函数用法

请大侠帮我解惑,谢谢!

import pickle

shoplistfile='shoplist.data'
shoplist=['apple','banana','mango']

f=open(shoplistfile, 'wb')
pickle.dump(shoplist,f)#把对象储存到打开的文件中
f.close()

del shoplist

f=open(shoplistfile)
storedlist=pickle.load(f)
print(storedlist)

结果如下报错:

D:\python\python.exe D:/python/程序/pickle.py
Traceback (most recent call last):
File "D:/python/程序/pickle.py", line 1, in
import pickle
File "D:\python\程序\pickle.py", line 7, in
pickle.dump(shoplist,f)#把对象储存到打开的文件中
AttributeError: module 'pickle' has no attribute 'dump'

查看全部
missy_609
missy_609
2017/07/24 08:52
  • python
  • 点赞
  • 收藏
  • 回答
    私信

5个回复