Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Python and UTF-8 text encoding on OSX' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Python and UTF-8 text encoding on OSX
Authored by: boxcarl on Jul 23, '10 11:42:55PM
As the other commenters have noted, in Python 2 you can print things of class str directly to the terminal (which are bytestrings) but things of class unicode need to be converted to bytestrings (str) before they can be printed. The easiest way to do this is myunicodestring.encode("utf-8") but if you want to be able to say “print myunicodestring” without encoding first in the interactive shell, you can try putting export LC_CTYPE=en_US.utf-8 in your .bash_profile, just so that Python knows that Terminal.app wants its input (Python’s output) to be in UTF-8. I think newer versions of Terminal do this automatically (10.6), but older ones did not.

[ Reply to This | # ]