WTF? Printing unicode strings

Robert Kern robert.kern at gmail.com
Fri May 19 14:12:18 EDT 2006


skip at pobox.com wrote:
>     Robert> Because sys.stdout.encoding isn't determined by your Python
>     Robert> configuration, but your terminal's.
> 
> Learn something every day.  I take it "646" is an alias for "ascii" (or vice
> versa)?
> 
>     % python
>     Python 2.4.2 (#1, Feb 23 2006, 12:48:31)
>     [GCC 3.4.1] on sunos5
>     Type "help", "copyright", "credits" or "license" for more information.
>     >>> import sys
>     >>> sys.stdout.encoding
>     '646'
>     >>> import codecs
>     >>> codecs.lookup("646")
>     (<built-in function ascii_encode>, <built-in function ascii_decode>, <class encodings.ascii.StreamReader at 0x819aa4c>, <class encodings.ascii.StreamWriter at 0x819aa1c>)

Yes. In encodings/aliases.py in the standard library:

"""
aliases = {

    # Please keep this list sorted alphabetically by value !

    # ascii codec
    '646'                : 'ascii',

"""

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco




More information about the Python-list mailing list