简体   繁体   English

TypeError:需要一个类似字节的对象,而在用pickle加载时不是'str'

[英]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.

相关问题 TypeError:需要一个类似字节的对象,而不是“str” - TypeError: a bytes-like object is required, not 'str' TypeError:需要类似字节的 object,而不是“str”? - TypeError: a bytes-like object is required, not 'str'? 需要一个类似字节的对象,而不是'str':TypeError - a bytes-like object is required, not 'str' : TypeError TypeError:需要一个类似字节的对象,而不是'str' - TypeError: a bytes-like object is required, not 'str' TypeError:在Python 3中打开Python 2 Pickle文件时,需要一个类似字节的对象,而不是'str' - TypeError: a bytes-like object is required, not 'str' when opening Python 2 Pickle file in Python 3 错误消息:TypeError:需要一个类似字节的对象,而不是在Python中使用Pickle接收到的“ str” - Error message: TypeError: a bytes-like object is required, not 'str' received using Pickle in Python 需要一个类似字节的对象,在pickle python 3.6中不需要'str' - a bytes-like object is required, no 'str' with pickle python 3.6 TypeError:需要一个类似字节的对象,而不是“ str”,但类型是“ bytes” - TypeError: a bytes-like object is required, not 'str' but type is 'bytes' TypeError:需要类似字节的 object,不是“str”,但类型显示字节 - TypeError: a bytes-like object is required, not 'str' but type shows bytes TypeError:需要一个类似字节的对象,而不是'str'python - TypeError: a bytes-like object is required, not 'str' python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM