STINNER Victor added the comment:

> There is a big difference between environment variables and internal calls: 
> Environment variables are user-space while builtin/library functions are 
> developer-space.

You can reopen sys.stdout with a different encoding and replace sys.stdout. I 
don't remember the exact recipe, it's tricky if you want portable code (you 
have to take care of newline).

For example, I wrote:
http://hg.python.org/cpython/file/ebe28dba4a78/Lib/test/regrtest.py#l895

But you can avoid reopening the file using stdout.detach().

> In theory this makes already my ticket invalid. Well, but now I would wish 
> print() would allow to choose the encoding like open() too^^

Many options were already proposed. Another way, less convinient is to use 
sys.stdout.buffer.write("text".encode(encoding)) (you have to flush sys.stdout 
before, and flush the buffer after, to avoid inconsistencies between the 
TextIOWrapper and the BufferedWriter).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue19846>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to