I want to open a txt file for processing, I get an error: utf-8 'codec can't decode byte 0xd0, everything is in Unicode, but there may be lines like this, how to make python not interpret them as bytes? maybe I don't understand something?

  • add error output and the way you open the file. - approximatenumber
  • example = open ('test.txt', 'r') example.
  • In what encoding is the text saved to a file? Create a minimal example of a file that leads to an error and add bytes to the response as is: print(open("text.txt", "rb").read()) - jfs

1 answer 1

 with codecs.open(file_name, "r",encoding='utf-8', errors='ignore') as fdata: 
  • I do not really understand how to work with this design - FFF3_ZE
  • Do not use codecs. The author has the usual open () reads Unicode (which Python 3 indicates). You can specify an error handler there. Even on Python 2.7, io.open should be used instead of codecs.open in most cases. - jfs