I resolved this problem, but I'd like to understand the why.
I am on a Windows 10 pc running Python 3.9.6. I had a simple text file with a single line in it, which was just:
Fifty_50
I had been running a small python utility file for some time opening files like this and parsing through the contents without any issue, but I had been using Python 3.7. My code was very simple:
with open(companyfile) as companies:
for company in companies:
...
When I ran this yesterday, I started getting garbage instead of the text out of this simple one line file. I decided it was likely because I wasn't providing encoding and changed the code to:
with open(companyfile, 'r', encoding='utf-8') as companies:
That gave me this error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Finally, I tried utf-16, and the file opened and processed normally.
So my question is do I have to always specify utf-16 now that I'm using Python 3.9? There were no special characters in the simple file that I was trying to open; so I don't understand why it had a problem.
Any insight would be appreciated.
Thanks--
Al