Python 2.7 - AttributeError:'module'对象没有属性'load'

时间:2015-08-21 23:32:59

标签: python serialization deserialization pickle

我正在使用Python 2.7而且不知道为什么我一直收到此加载错误?

import pickle
f=open("C:\\Users\\James\\Desktop\\banner.p",'rb')
storedlist=pickle.load(f)
for i in storedlist:
    print (i)

Traceback (most recent call last):
  File "C:/Users/James/Desktop/pickle.py", line 1, in <module>
    import pickle
  File "C:/Users/James/Desktop\pickle.py", line 3, in <module>
    storedlist=pickle.load(f)
AttributeError: 'module' object has no attribute 'load'

1 个答案:

答案 0 :(得分:8)

  

文件&#34; C:/ Users / James / Desktop / pickle.py &#34;,第1行,

这是因为您正在命名文件pickle.py,因此Python会将您的文件混淆为原始pickle模块。

解决方案:重命名脚本文件名并删除pickle.pyc