UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 10442: character maps to <undefined>
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Tue May 29 12:20:36 EDT 2018
On Tue, 29 May 2018 14:04:19 +0200, Peter J. Holzer wrote:
> The OP has one file.
We don't know that. All we know is that he had one file which he was
unable to read. For all we know, he has a million files, and this was
merely the first of many failures.
> He wants to read it. The very fact that he wants to
> read this particular file makes it very likely that he knows something
> about the contents of the file. So he has domain knowledge.
An unjustified assumption. I've wanted to read many files with only the
vaguest guess of what they might contain.
As for his domain knowledge, look again at the OP's post. His solution
was to paper over the error, make the error go away, by moving to Python
2 which is more lax about getting the encoding right:
"i actually got my script to function by running it in python 2.7"
So he didn't identify the correct encoding, nor did he use an error
handler, or fix the bug in his code. He just downgraded to an older
version of Python, because it made the exception (but not the error) go
away.
My prediction is that he has replaced an explicit exception with a silent
failure, preferring mojibake to actually dealing with the problem.
--
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson
More information about the Python-list
mailing list