这应该非常简单:我过去经常使用pickle
。这次出了什么问题?
import pickle
with open('data/cifar-10-batches-py/data_batch_1','rb') as f:
dat = pickle.load(f)
AttributeError: 'function' object has no attribute 'load'
以下内容也失败(如果load
被注释掉了)
with open ('data/cifar-10-batches-py/small_batch','wb') as f:
pickle.dump(images[0:100],f, protocol=pickle.HIGHEST_PROTOCOL)
AttributeError: 'function' object has no attribute 'dump'
所以似乎pickle
没有被正确导入?
这是python 2.7.3
答案 0 :(得分:0)
pickle
被以下内容遮蔽(我未在OP
中加入,因为我不知道它是否相关
from cifar import *
它有
# pickle object
# obj: object to pickle
# file_path: file path to store object at in binary cpython blob
def pickle(obj, file_path):
with open(file_path, "wb") as fo:
cPickle.dump(obj, fo)
值得怀疑的是,cifar
以这种方式创建了一个名为pickle
的方法。所以,我需要更加谨慎地做
from some_library import *