Interpreting string containing \u000a

Francis Girard francis.girardpython at gmail.com
Wed Jun 18 08:27:07 EDT 2008


Thank you very much ! I didn't know about this 'unicode-escape'. That's
great!

Francis

2008/6/18 Duncan Booth <duncan.booth at invalid.invalid>:

> "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
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080618/b78cf9f3/attachment-0001.html>


More information about the Python-list mailing list