[Pythonmac-SIG] How to print unicode to OS-X Terminal.app

skip at pobox.com skip at pobox.com
Thu Feb 14 01:08:27 CET 2008


    Chris> So how to I get Python to convert to utf-8 with a print
    Chris> statement, instead of ascii?

The print statement can't do it directly, but you can encode Unicode objects
using different charsets then print the result.  Try this:

    >>> unicode("\xef", "latin-1")
    u'\xef'
    >>> unicode("\xef", "latin-1").encode("utf-8")
    '\xc3\xaf'
    >>> print unicode("\xef", "latin-1").encode("utf-8")
    ï

-- 
Skip Montanaro - skip at pobox.com - http://www.webfast.com/~skip/


More information about the Pythonmac-SIG mailing list