我正在尝试使用这个程序加载Python 3.2中链接的MNIST数据集: import pickle import gzip import numpy with gzip.open('mnist.pkl.gz', 'rb') as f: l = list(pickle.load(f)) print(l) 不幸的是,它给了我错误: Traceback (most recent call last): File "mnist.py", line 7, in <module> train_set, valid_set, test_set = pickle.load(f) UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 614: ordinal not in range(128) 然后我尝试在Python 2.7中解码pickle文件,并对其进行重新编码。 所以,我用Python 2.7运行这个程序: import pickle import […]
我正在使用python3.3,并尝试pickle一个简单的字典时,我有一个神秘的错误。 这里是代码: import os import pickle from pickle import * os.chdir('c:/Python26/progfiles/') def storvars(vdict): f = open('varstor.txt','w') pickle.dump(vdict,f,) f.close() return mydict = {'name':'john','gender':'male','age':'45'} storvars(mydict) 我得到: Traceback (most recent call last): File "C:/Python26/test18.py", line 31, in <module> storvars(mydict) File "C:/Python26/test18.py", line 14, in storvars pickle.dump(vdict,f,) TypeError: must be str, not bytes