I am writing a code to extract specific lines from a text file into an output file, and here is what my code looks like:
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('-----------------------------------------------------')
I keep getting this error:
Traceback (most recent call last): File "/Users/Sam/Desktop/readstuff.py", line 3, in for line in infile: File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 154: ordinal not in range(128)
What should I do?