Interpreting string containing \u000a

Duncan Booth duncan.booth at invalid.invalid
Wed Jun 18 08:12:21 EDT 2008


"Francis Girard" <francis.girard07 at gmail.com> wrote:

> I have an ISO-8859-1 file containing things like
> "Hello\u000d\u000aWorld", i.e. the character '\', followed by the
> character 'u' and then '0', etc.
> 
> What is the easiest way to automatically translate these codes into
> unicode characters ?
> 

>>> s = r"Hello\u000d\u000aWorld"
>>> print s
Hello\u000d\u000aWorld
>>> s.decode('iso-8859-1').decode('unicode-escape')
u'Hello\r\nWorld'
>>> 

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list