I had a script I was trying to port from python2 to python3.
I did read through the porting documentation, https://docs.python.org/3/howto/pyporting.html.
My original python2 script used open('filename.txt)
. In porting to python3 I updated it to io.open('filename.txt')
. Now when running the script as python2 or python3 with the same input files I get some errors like UnicodeDecodeError: 'utf-8' codec can't decode byte 0x93 in position 793: invalid start byte
.
Does python2 open
have less strict error checking than io.open
or does it use a different default encoding? Does python3 have an equivalent way to call io.open
to match python2 built in open
?
Currently I've started using f = io.open('filename.txt', mode='r', errors='replace')
which works. And comparing output to the original python2 version, no important data was lost from the replace errors.