Reading Text Files with Python

Try different encoding to successfully read text files with Python

Yancy Dennis
Python in Plain English
2 min readOct 1, 2022

--

For some of my gigs, I have to process many text files. I have noticed that the text files sometimes have different encoding. I am not sure why. Typically, text files match the utf-8 format. However, sometimes, Windows-1252 is present.

As you might imagine, the read does not work if you specify the wrong encoding — you will receive an error message. Of course, there are other types of encoding for text files but I have not encountered them…

--

--