On Apr 18, 6:36 pm, 7stud <[EMAIL PROTECTED]> wrote:
> On Apr 18, 5:38 pm, [EMAIL PROTECTED] 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

Or maybe you want this:

u_str = u'hell\u00F6 w\u00F6rld'
regular_str = u_str.encode('utf-8')
print repr(regular_str)

--output:--
'hell\_x_c3\_x_b6 w\_x_c3\_x_b6rld'
#underscores added to keep your browser from rendering the utf-8
characters
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to