[Python]attributeError:'module' object has no attribute 'dump'

简介: 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/42345623 【问题】【代码】文件名:pickle.
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SunnyYoona/article/details/42345623

【问题】


【代码】

文件名:pickle.py

# 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了




目录
相关文章
|
29天前
|
计算机视觉 Python
解决 NoneType‘ object has no attribute ‘astype’ 问题
解决 NoneType‘ object has no attribute ‘astype’ 问题
24 0
|
5月前
|
存储 JSON 数据格式
数据集加载时报错'dict' object has no attribute 'requests‘
数据集加载时报错'dict' object has no attribute 'requests‘
107 5
|
3月前
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
358 0
|
1月前
|
存储 设计模式 Python
Python中的类(Class)和对象(Object)
Python中的类(Class)和对象(Object)
27 0
|
3月前
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
85 0
|
3月前
|
Python
Python学习 -- 根类object
Python学习 -- 根类object
16 0
|
4月前
|
数据采集
运行爬虫时报错AttributeError—— 'str' object has no attribute 'capabilities'
运行爬虫时报错AttributeError—— 'str' object has no attribute 'capabilities'
216 0
|
4月前
'WebDriver' object has no attribute 'find_element_by_tag_name'
'WebDriver' object has no attribute 'find_element_by_tag_name'
110 0
|
4月前
|
Kubernetes Python 微服务
Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding
Python3异常-AttributeError: module 'sys' has no attribute 'setdefaultencoding
45 0
|
5月前
|
Java
java判断Object对象是否为空demo
java判断Object对象是否为空demo