catch UnicodeDecodeError

Chris Angelico rosuav at
Thu Jul 26 11:46:14 CEST 2012

On Thu, Jul 26, 2012 at 5:46 PM, Jaroslav Dobrek
<jaroslav.dobrek at> wrote:
> My problem is solved. What I need to do is explicitly decode text when
> reading it. Then I can catch exceptions. I might do this in future
> programs.

Apologies if it's already been said (I'm only skimming this thread),
but ISTM that you want to open the file in binary mode. You'll then
get back a bytes() instead of a str(), and you can attempt to decode
it separately. You may then need to do your own division into lines
that way, though.


More information about the Python-list mailing list