How to print a unicode string?

damonwischik at gmail.com damonwischik at gmail.com
Sat Apr 19 01:38:04 CEST 2008


I'd like to print out a unicode string.

I'm running Python inside Emacs, which understands utf-8, so I want to
force Python to send utf-8 to sys.stdout.

>From what I've googled, I think I need to set my locale. I don't
understand how.

import locale
print locale.getlocale()
--> (None,None)
print locale.getdefaultlocal()
--> ('en_GB','cp1252')
print locale.normalize('en_GB.utf-8')
--> en_GB.UTF8
locale.setlocale(locale.LC_ALL,'en_GB.UTF8')
-->  locale.Error: unsupported locale setting

I'd be grateful for advice.
Damon.



More information about the Python-list mailing list