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

Discussion in 'Python' started by Romano Giannetti, Feb 25, 2008.

  1. 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/python-dev/2007-May/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
     
    Romano Giannetti, Feb 25, 2008
    #1
    1. Advertising

  2. Romano Giannetti

    Guest


    > 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? :)
     
    , Feb 25, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Walter L. Preuninger II

    literal escape sequence conversion to raw

    Walter L. Preuninger II, Jan 5, 2004, in forum: C Programming
    Replies:
    6
    Views:
    488
    Kevin Goodsell
    Jan 5, 2004
  2. Achim Domma
    Replies:
    3
    Views:
    623
    Sjoerd Mullender
    Feb 17, 2004
  3. ldng
    Replies:
    3
    Views:
    1,875
    Tim Golden
    May 10, 2007
  4. Romano Giannetti
    Replies:
    7
    Views:
    391
    rmano
    Mar 7, 2008
  5. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    392
    Anonieko Ramos
    Sep 27, 2004
Loading...

Share This Page