Yet another unicode WTF

Ben Finney ben+python at
Fri Jun 5 02:11:54 EDT 2009

"Gabriel Genellina" <gagsl-py2 at> writes:

> Python knows the terminal encoding (or at least can make a good
> guess), but a file may use *any* encoding you want, completely
> unrelated to your terminal settings.

It may, yes, and the programmer is free to specify any encoding.

> So when stdout is redirected, Python refuses to guess its encoding;

But Python doesn't have to guess; the terminal encoding is as specified
in either case, no?

> see the PYTHONIOENCODING environment variable.

For the standard streams, the specified terminal encoding available to
every program makes the most sense — certainly more sense than a
Python-specific variable, or the “default to ASCII” of the current

 \        “Holy uncanny photographic mental processes, Batman!” —Robin |
  `\                                                                   |
_o__)                                                                  |
Ben Finney

More information about the Python-list mailing list