2
votes

I used to be able to perform file io operations on plain text files using python 3, however a few days ago I encountered errors whenever I tried to use the readlines() method on plain text files.

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 0xef in position 0: ordinal not in range(128)

I get this above error message whenever I try to use the readlines() method, previously it worked as it was supposed to.

1
Does the file you are trying to read contain non-ascii characters? Thats what the error is saying - stackErr
Do you have an example of your code with context? - Vic
It looks like you're somehow trying to use the ascii encoding to read a non-ascii file. Just read it as-is and python-3 should use the 'utf-8' encoding by default - kerwei

1 Answers

1
votes

Are you specifying the encoding when opening the file?

with open('file', 'r', encoding='utf-8') as f:
      ...