How to 'de-slashify' a string?

Piet van Oostrum piet at cs.uu.nl
Sat Aug 22 09:52:44 EDT 2009


>>>>> Vlastimil Brom <vlastimil.brom at gmail.com> (VB) wrote:

>>>>> decoded = '\\303\\266'.decode("string_escape")
>>>>> decoded
>VB> '\xc3\xb6'
>>>>> print decoded
>VB> ö
>>>>> print '\303\266'
>VB> ö
>>>>> 

>VB> It might be an IDLE issue, but it still isn't one unicode glyph.

>VB> I guess, you have to ensure, that the input data is valid and the
>VB> right encoding is used.

>>> decoded = '\\303\\266'.decode("string_escape").decode('utf-8')
>>> decoded
u'\xf6'
>>> print decoded
ö

-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list