Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:需要类似字节的对象,而不是';str';从文件中读取时_Python_String_Python 3.x_Byte_File Handling - Fatal编程技术网

Python TypeError:需要类似字节的对象,而不是';str';从文件中读取时

Python TypeError:需要类似字节的对象,而不是';str';从文件中读取时,python,string,python-3.x,byte,file-handling,Python,String,Python 3.x,Byte,File Handling,我正试图使用文件中的数据集在ML中实现我的项目 authors_file_handler = open(authors_file, "r") authors = pickle.load(authors_file_handler) authors_file_handler.close() 在这之后,我在这行中遇到了错误 authors=pickle.load(authors\u file\u处理程序) 您需要以二进制读取模式打开文件: authors_file_handler = open(au

我正试图使用文件中的数据集在ML中实现我的项目

authors_file_handler = open(authors_file, "r")
authors = pickle.load(authors_file_handler)
authors_file_handler.close()
在这之后,我在这行中遇到了错误

authors=pickle.load(authors\u file\u处理程序)


您需要以二进制读取模式打开文件:

authors_file_handler = open(authors_file, "rb") # Note the added 'b'
authors = pickle.load(authors_file_handler)
authors_file_handler.close()
pickle.load()
中:

参数文件必须有两个方法,一个read()方法采用 整数参数,以及不需要参数的readline()方法。 这两种方法都应该返回字节。因此,文件可以是磁盘上的文件 打开进行二进制读取、io.BytesIO对象或任何其他自定义 满足此接口的对象


您在哪一行得到错误?请提供完整的回溯。请尝试:
authors=pickle.load(字节(authors\u file\u handler,encoding=“utf-8”)
authors_file_handler = open(authors_file, "rb") # Note the added 'b'
authors = pickle.load(authors_file_handler)
authors_file_handler.close()