file.write() of non-ASCII characters differs in Interpreted Python than in script run

dieter dieter at
Wed Aug 26 07:51:42 CEST 2015

RAH <rene.heymans at> writes:

> I experienced an incomprehensible behavior (I've spent already many hours on this subject): the `file.write('string')` provides an error in run mode and not when interpreted at the console.

Maybe, I can explain the behavior: the interactive interpreter uses magic
to determine the console's encoding and automatically uses this
for console output. No such magic in non-interactive interpreter use.
Therefore, you can get "UnicodeEncoding" problems in non-interactive use
which you do not see in interactive use.

More information about the Python-list mailing list