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

简介:

【问题】


【代码】

文件名: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了




目录
相关文章
|
1月前
|
计算机视觉 Python
解决 NoneType‘ object has no attribute ‘astype’ 问题
解决 NoneType‘ object has no attribute ‘astype’ 问题
28 0
|
3月前
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
AttributeError: 'NoneType' object has no attribute 'to_capabilities'
364 0
|
9天前
|
Python
IDA3.12版本的python,依旧报错IDAPython: error executing init.py.No module named ‘impRefer to the message win
IDA3.12版本的python,依旧报错IDAPython: error executing init.py.No module named ‘impRefer to the message win
|
1月前
|
存储 设计模式 Python
Python中的类(Class)和对象(Object)
Python中的类(Class)和对象(Object)
29 0
|
1月前
|
文字识别 Python
python代码运行报错:No module named 'aliyunsdkcore'
用python调用阿里云图片OCR识别,使用的是阿里云官方给的传本地图片文件进行检测的代码,运行报错:No module named 'aliyunsdkcore'。在pycharm python软件包和终端里安装aliyunsdkcore这个模块都失败了。
|
3月前
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
AttributeError ‘NoneType‘ object has no attribute ‘to_capabilities‘
92 0
|
3月前
|
Python
Python学习 -- 根类object
Python学习 -- 根类object
16 0
|
4月前
|
数据采集
运行爬虫时报错AttributeError—— 'str' object has no attribute 'capabilities'
运行爬虫时报错AttributeError—— 'str' object has no attribute 'capabilities'
243 0
|
14天前
|
安全 Java 数据处理
Python网络编程基础(Socket编程)多线程/多进程服务器编程
【4月更文挑战第11天】在网络编程中,随着客户端数量的增加,服务器的处理能力成为了一个重要的考量因素。为了处理多个客户端的并发请求,我们通常需要采用多线程或多进程的方式。在本章中,我们将探讨多线程/多进程服务器编程的概念,并通过一个多线程服务器的示例来演示其实现。
|
14天前
|
程序员 开发者 Python
Python网络编程基础(Socket编程) 错误处理和异常处理的最佳实践
【4月更文挑战第11天】在网络编程中,错误处理和异常管理不仅是为了程序的健壮性,也是为了提供清晰的用户反馈以及优雅的故障恢复。在前面的章节中,我们讨论了如何使用`try-except`语句来处理网络错误。现在,我们将深入探讨错误处理和异常处理的最佳实践。