今天写了一个pickle.py的文件练习pickle模块,代码如下:
import pickle dic = {"linga": ('football',)} dic2 = {"saya": ('game')} dic3 = {"viper": ('play')} with open("pickles.pickle", 'wb') as handle: pickle.dump(dic, handle) pickle.dump(dic2, handle) pickle.dump(dic3, handle) pickle.dump(dic, handle) pickle.dump(dic2, handle)
然后执行代码后就这个样子:
C:Python36python.exe D:/linga/Documents/Python/Module/pickle.py Traceback (most recent call last): File "D:/linga/Documents/Python/Module/pickle.py", line 49, in <module> import pickle File "D:lingaDocumentsPythonModulepickle.py", line 53, in <module> print(pickle.dump(dic)) AttributeError: module 'pickle' has no attribute 'dump' Process finished with exit code 1
这个报错是说pickle这个模块没有dump属性,这个报错的原因是应为自己练习的pickle的文件名pickle.py和标准库pickle命名冲突了,需要修改掉自己写的文件名
2018-07-05 20:48:24