使用Python 3.5,抛出错误:TypeError:需要一个类似字节的对象,而不是'str'

罗希特

我正在使用Spyder Python IDE,Python 3.5版并尝试运行具有代码的python文件

import pickle

enron_data = pickle.load(open("../final_project/final_project_dataset.pkl", "r"))

但是在运行时,它会引发以下错误

TypeError:需要一个类似字节的对象,而不是'str'

弘主角

您需要以二进制打开文件(因此read它返回bytes而不是str):

open("../final_project/final_project_dataset.pkl", "rb")

(请注意'b'模式中的附加项)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python 3-TypeError:需要一个类似字节的对象,而不是'str'

Python 2到3“ TypeError:需要一个类似字节的对象,而不是'str'”

Python3 TypeError:需要一个类似字节的对象,而不是“str”

Python3 .replace产生TypeError:需要一个类似字节的对象,而不是'str'

Python 3,TypeError:需要一个类似字节的对象,而不是'str'

TypeError:需要一个类似字节的对象,而在Python 3中打开Python 2 Pickle文件时不是'str'

TypeError:在Python3中写入文件时需要一个类似字节的对象,而不是'str'

类型错误:需要一个类似字节的对象,而不是无服务器和 Python3 的“str”

Python3写入gzip文件-memoryview:需要一个类似字节的对象,而不是'str'

Python 3 升级,需要一个类似字节的对象,而不是“str”

Python错误:TypeError:需要一个类似字节的对象,而不是'str'

TypeError:需要一个类似字节的对象,而不是'str'–用Python保存JSON数据

Python 3.7 TypeError:需要一个类似字节的对象,而不是'str'

python 3.5:“ TypeError:memoryview:需要一个类似字节的对象,而不是'str'”

TypeError:需要一个类似字节的对象,而在python和CSV中不是'str'

TypeError:需要一个类似字节的对象,而在python和CSV中不是'str'

需要一个类似字节的对象,而不是python中的“ str”错误

类型错误:需要一个类似字节的对象,而不是使用 BytesIO 的“str”

Python 3.5 TypeError:需要一个类似字节的对象,而不是使用truncate过滤器的'str'

TypeError:在Python 3.5.1中使用REST时需要一个类似字节的对象,而不是'str'

使用python计算excel中的重复行,并且我收到错误TypeError:需要一个类似字节的对象,而不是'str'

python3:类型错误:需要类似字节的对象,而不是“str”

类型错误:需要一个类似字节的对象,而不是“int”python3

Python 3.6:TypeError:在尝试打印页面中的所有链接时,需要一个类似字节的对象,而不是'str'

错误:需要一个类似字节的对象,而不是'str'

Python2 到 Python3 的转换?类型错误:内存视图:需要类似字节的对象,而不是“str”

如何解决Json错误:TypeError:需要一个类似字节的对象,而不是'str'

期望在python3中抛出错误,因为“必须在str中,而不是字节中”

Python gnupg“类型错误:需要类似字节的对象,而不是'str'”