Python 从文件中读取文件

Python 从文件中读取文件,python,Python,从项目 我尝试运行此代码 但是当它读取文件python process_data.py./GoogleNews-vectors-negative300.bin./articles.csv./mairese.csv时会出现问题 但是,我收到此错误: C:\personality-detection-master>python process_data.py ./GoogleNews-vectors-nega tive300.bin ./essays.csv ./mairesse.csv WA

从项目

我尝试运行此代码

但是当它读取文件python process_data.py./GoogleNews-vectors-negative300.bin./articles.csv./mairese.csv时会出现问题

但是,我收到此错误:

C:\personality-detection-master>python process_data.py ./GoogleNews-vectors-nega
tive300.bin ./essays.csv ./mairesse.csv
WARNING (theano.configdefaults): g++ not available, if using conda: `conda insta
ll m2w64-toolchain`
C:\Users\nathalie\Miniconda3\lib\site-packages\theano\configdefaults.py:560: UserWa
rning: DeprecationWarning: there is no c++ compiler.This is deprecated and with
Theano 0.11 a c++ compiler will be mandatory
  warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to exe
cute optimized C-implementations (for both CPU and GPU) and will default to Pyth
on implementations. Performance will be severely degraded. To remove this warnin
g, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS fu
nctions.
Traceback (most recent call last):
  File "process_data.py", line 163, in <module>
    revs, vocab = build_data_cv(data_folder, cv=10, clean_string=True)
  File "process_data.py", line 21, in build_data_cv
    for line in csvreader:
_csv.Error: iterator should return strings, not bytes (did you open the file in
text mode?)
我没有打开文件的任何地方。我能做什么

我应该更新代码吗

在上一代码中更改后,rb为r

C:\personality-detection-master>python process_data.py ./GoogleNews-vectors-nega
tive300.bin ./essays.csv ./mairesse.csv
WARNING (theano.configdefaults): g++ not available, if using conda: `conda insta
ll m2w64-toolchain`
C:\Users\nathalie\Miniconda3\lib\site-packages\theano\configdefaults.py:560: UserWa
rning: DeprecationWarning: there is no c++ compiler.This is deprecated and with
Theano 0.11 a c++ compiler will be mandatory
  warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to exe
cute optimized C-implementations (for both CPU and GPU) and will default to Pyth
on implementations. Performance will be severely degraded. To remove this warnin
g, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS fu
nctions.
Traceback (most recent call last):
  File "process_data.py", line 163, in <module>
    revs, vocab = build_data_cv(data_folder, cv=10, clean_string=True)
  File "process_data.py", line 21, in build_data_cv
    for line in csvreader:
  File "C:\Users\nathalie\Miniconda3\lib\encodings\cp1253.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8e in position 1858: cha
racter maps to <undefined>
C:\personality detection master>python进程_data.py./GoogleNews向量nega
tive300.bin./articles.csv./mairese.csv
警告(theano.configdefaults):如果使用conda:`conda insta,则g++不可用
ll m2w64工具链`
C:\Users\nathalie\Miniconda3\lib\site packages\theano\configdefaults.py:560:UserWa
ReNe:Debug警告:没有C++编译器。这是不赞成的。
TeaNAN0.11 A+C++编译器将是强制性的
警告。“警告”:“没有C++编译器。”
警告(theano.configdefaults):未检测到g++!theano将无法执行
可爱的优化C实现(适用于CPU和GPU),默认为Pyth
在实现上。性能将严重降级。若要删除此警告,请执行以下操作:
g、 将无标志cxx设置为空字符串。
警告(theano.tensor.blas):对blas fu使用基于NumPy C-API的实现
不合作。
回溯(最近一次呼叫最后一次):
文件“process_data.py”,第163行,在
revs,vocab=build\u data\u cv(data\u folder,cv=10,clean\u string=True)
文件“process_data.py”,第21行,内置数据
对于csvreader中的线路:
文件“C:\Users\nathalie\Miniconda3\lib\encodings\cp1253.py”,第23行,解码
返回编解码器.charmap\u解码(输入、自身错误、解码表)[0]
UnicodeDecodeError:“charmap”编解码器无法解码1858:cha位置的字节0x8e
莱克特映射到
错误是:

_csv.Error: iterator should return strings, not bytes (did you open the file in
text mode?)

您以二进制模式(“rb”)打开了文件,应该以文本模式(“r”)打开它。

谢谢。我改为r,但在同一行中仍然存在读取问题。我用新错误更新了问题
_csv.Error: iterator should return strings, not bytes (did you open the file in
text mode?)