Python and UTF-8

Michael Ströder michael at stroeder.com
Thu Jan 3 17:31:57 EST 2002


Matthias Huening wrote:
> 
> >>> t = 'Mühsam ernährt sich das Eichhörnchen.'
> >>> print t.upper()
> MÜHSAM ERNÄHRT SICH DAS EICHHÖRNCHEN.
> >>> tu = unicode(t, 'latin-1').encode('utf-8')
> >>> print tu.upper()
> MüHSAM ERNäHRT SICH DAS EICHHöRNCHEN.
> >>>
> ----------------------
> 
> This should work, I think. But it doesn't.
> Did I miss something?

>>> tu = unicode(t, 'latin-1')
>>> print tu.upper().encode('latin-1')
MÜHSAM ERNÄHRT SICH DAS EICHHÖRNCHEN.
>>> tu.upper().encode('utf-8')
'M\xc3\x9cHSAM ERN\xc3\x84HRT SICH DAS EICHH\xc3\x96RNCHEN.'
>>>

Ciao, Michael.



More information about the Python-list mailing list