[英]TypeError: a bytes-like object is required, not 'str' while loading with pickle
I'm using Python 3.6 and Spyder (Anaconda). 我正在使用Python 3.6和Spyder(Anaconda)。 I have tried many things but nothing worked out. 我尝试了很多事情,但没有解决。 I don't know why this error is coming always to me while loading with pickle. 我不知道为什么在加载泡菜时总是会出现此错误。
filename = "allfeatures.txt"
allfeatures = open(filename, 'r').read()
with open(filename) as f:
allfeatures = list(f)
allconcat = np.vstack(list(allfeatures.values()))
TypeError Traceback (most recent call last)
AttributeError: 'list' object has no attribute 'values'
You need to open your file as a binary file: 您需要以二进制文件打开文件:
pickle.loads(open("accounts.txt", 'rb').read())
Otherwise, it's using an str
to read the data. 否则,它使用str
读取数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.