This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Sworddragon, a.badger, bkabrda, larry, lemburg, loewis, ncoghlan, pitrou, r.david.murray, serhiy.storchaka, terry.reedy, vstinner
Date 2013-12-09.13:55:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1386597331.92.0.0249630006767.issue19846@psf.upfronthosting.co.za>
In-reply-to
Content
> 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).
History
Date User Action Args
2013-12-09 13:55:31vstinnersetrecipients: + vstinner, lemburg, loewis, terry.reedy, ncoghlan, pitrou, larry, a.badger, r.david.murray, Sworddragon, serhiy.storchaka, bkabrda
2013-12-09 13:55:31vstinnersetmessageid: <1386597331.92.0.0249630006767.issue19846@psf.upfronthosting.co.za>
2013-12-09 13:55:31vstinnerlinkissue19846 messages
2013-12-09 13:55:31vstinnercreate