我正在编写一个代码,用于将特定行从文本文件中提取到输出文件中,这就是我的代码:
with open('output.txt', 'w') as outfile:
with open('testfile.txt') as infile:
for line in infile.readlines:
if 'Emotion' in line or 'PANS.RESP' in line:
outfile.write(line)
outfile.write('-----------------------------------------------------')
我一直收到此错误:
Traceback(最近一次调用最后一次):文件 " /Users/Sam/Desktop/readstuff.py" ;,第3行,in for infile:File" /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", 第26行,在解码中 return codecs.ascii_decode(input,self.errors)[0] UnicodeDecodeError:' ascii'编解码器不能将字节0xe2解码到位 154:序数不在范围内(128)
我该怎么办?