Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Embedding a literal "\u" in a unicode raw string.

Reply
Thread Tools

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

 
 
Romano Giannetti
Guest
Posts: n/a
 
      02-25-2008
Thinker <thinker <at> branda.to> writes:

>
>
> > 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 backslash '\' is a meta-char that escapes the string. You can
> escape the char as following string
> u"....\\u....'
> insert another '\' before it.
>


(Answering this and the other off thread answer by Diez)

Well, I have simplified too much. The problem is, when writing LaTeX snippets, a
lot of backslashed are involved. So the un-raw string is difficult to read
because all those doubled \\, and the raw string is just handy. Moreover, that
way I can copy-and-paste LaTeX code between ur""" """ marks,

Searching more, I even found a thread in python-dev where Guido himself seemed
convinced that this "\u" interpratation in raw strings is at least a bit
disappointing:

http://mail.python.org/pipermail/pyt...ay/073042.html

but I have seen later that it will still here in 3.0. That means that all my
unicode(r"\uparrow", "utf-8") will break... sigh.

Thanks anyway,

Romano


 
Reply With Quote
 
 
 
 
romano.giannetti@gmail.com
Guest
Posts: n/a
 
      02-25-2008

> unicode(r"\uparrow", "utf-8") will break... sigh.
>


Moreover, I checked with 2to3.py, and it say (similar case):

-ok_preamble = unicode(r"""
+ok_preamble = str(r"""
\usepackage[utf8]{inputenc}
\begin{document}
Añadidos:
""", "utf-8")

which AFAIK will give an error for the \u in \usepackage. Hmmm...
should I dare ask on the developer list?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: illegal line end in character literal in escaped unicode CARRIAGERETURN / NEW LINE Mark Space Java 0 05-15-2009 02:35 PM
Re: illegal line end in character literal in escaped unicode CARRIAGE RETURN / NEW LINE Andreas Leitgeb Java 0 05-15-2009 02:02 PM
Embedding a literal "\u" in a unicode raw string. Romano Giannetti Python 7 03-07-2008 03:18 PM
What's wrong with rpc-literal? Why use doc-literal? Anonieko Ramos ASP .Net Web Services 0 09-27-2004 09:06 AM
literal escape sequence conversion to raw Walter L. Preuninger II C Programming 6 01-05-2004 10:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57