How to print a unicode string?
7stud
bbxx789_05ss at yahoo.com
Fri Apr 18 20:36:12 EDT 2008
On Apr 18, 5:38 pm, damonwisc... at gmail.com wrote:
> 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.
u_str = u'hell\u00F6 w\u00F6rld' #o's with umlauts
print u_str.encode('utf-8')
--output:--
hellö wörld
More information about the Python-list
mailing list