更新时间:2022-08-12 18:57:17
# coding=utf-8 #持久存储 import pickle #b 以二进制的模式打开文件 with open('mydata.pickle','wb') as mysavedata: #用dump保存数据 pickle.dump([1,2,'three'],mysavedata) #b 以二进制的模式打开文件 with open('mydata.pickle','rb') as myreaddata: #使用load恢复数据 list = pickle.load(myreaddata) print list
主要问题就是源于这个文件名 pickle.py
因为这个文件名称和Python标准库中的模块名称冲突。所以你import pickle并不是导入标准库中的模块而是导入你自己创建的文件。
只要重新把文件名称改一下就OK了
[Python]attributeError:'module' object has no attribute 'dump'
在 Python 中是什么导致了这个错误(AttributeError: 'Mul' object has no attribute 'cos')?
Python 【精】AttributeError: 'Module' object has no attribute 'STARTF_USESHOWINDOW'
Interactive Broker Python API 显示错误:IB AttributeError: 'IBapi' object has no attribute 'connState'
AttributeError: 'dict_values' object has no attribute 'translate'
提示AttributeError: 'module' object has no attribute 'HTTPSHandler'解决方法
Python3下机器学习实战KNN代码出现AttributeError: ‘dict’ object has no attribute错误
[Python]attributeError:'module' object has no attribute 'dump'
AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'