Embedding a literal "\u" in a unicode raw string.

Romano Giannetti romano.giannetti at gmail.com
Mon Feb 25 06:39:14 EST 2008


Hi, 

while writing some LaTeX preprocessing code, I stumbled into this problem: (I
have a -*- coding: utf-8 -*- line, obviously) 

s = ur"añado $\uparrow$" 

Which gave an error because the \u escape is interpreted in raw unicode strings,
too. So I found that the only way to solve this is to write: 

s = unicode(r"añado $\uparrow$", "utf-8")

or 

s = ur"añado $\u005cuparrow$"

The second one is too ugly to live, while the first is at least acceptable; but
looking around the Python 3.0 doc, I saw that the first one will fail, too. 

Am I doing something wrong here or there is another solution for this? 

Romano 






More information about the Python-list mailing list