Message205694
> 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). |
|
Date |
User |
Action |
Args |
2013-12-09 13:55:31 | vstinner | set | recipients:
+ vstinner, lemburg, loewis, terry.reedy, ncoghlan, pitrou, larry, a.badger, r.david.murray, deleted250130, serhiy.storchaka, bkabrda |
2013-12-09 13:55:31 | vstinner | set | messageid: <1386597331.92.0.0249630006767.issue19846@psf.upfronthosting.co.za> |
2013-12-09 13:55:31 | vstinner | link | issue19846 messages |
2013-12-09 13:55:31 | vstinner | create | |
|