[Python-Dev] Proposal: new environment variable PYTHONSTDOUTENCODING (original) (raw)

M.-A. Lemburg mal at egenix.com
Tue May 20 12:36:39 CEST 2008


On 2008-05-20 12:16, Thomas Wouters wrote:

On Tue, May 20, 2008 at 10:41 AM, M.-A. Lemburg <mal at egenix.com> wrote:

On 2008-05-20 10:22, Martin v. Löwis wrote:

I'd like to propose a new environment variable PYTHONSTDOUTENCODING. This is meant to solve various problems that people had with Python not detecting their terminal encoding correctly; it would override any detection that Python would use for determining the encoding of stdout (and stdin - but that's less relevant in 2.x). How is this relevant for 2.x ? In 2.x, stdin and stdout are just files without any io wrappers around them. Writing Unicode to stdout will still use the default encoding ASCII to convert it to an 8-bit string. All other 8-bit strings will be passed to stdout as-is. You're forgetting about print; in Python 2.x, when stdout is connected to a terminal, the locale settings (typically the LANG, LCALL and LCCTYPE environment variables) are taken into account when 'print' writes to sys.stdout.

Thanks for reminding me. I had forgotten about that special case.

So "sys.stdout.write(unicode)" will always use the default encoding, whereas "print unicode" uses the sys.stdout.encoding, correct ?

Hmm, wouldn't it be better to always use .encoding and also make it adjustable from Python (it is adjustable from C) ?!

PYTHONSTDOUTENCODING could then provide the default to sys.stdout.encoding.

-- Marc-Andre Lemburg eGenix.com

Professional Python Services directly from the Source (#1, May 20 2008)

Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/


:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::

eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
        Registered at Amtsgericht Duesseldorf: HRB 46611


More information about the Python-Dev mailing list