Raw String Question

andrew cooke andrew at acooke.org
Fri Mar 13 06:04:05 EDT 2009


MRAB wrote:
> andrew cooke wrote:
>> MRAB wrote:
>> [...]
>>> The other special case is with \u in a Unicode string:
>>>
>>>  >>> ur"\u0041"
>>> u'A'
>>
>> this isn't true for 3.0:
>>
>>>>> r"\u0041"
>> '\\u0041'
>>
>> (there's no "u" because it's a string, not a bytes literal)
>>
>> and as far as i can tell, that's correct behaviour according to the
>> docs.
>>
>  From the 3.0 docs "Even in a raw string, string quotes can be escaped
> with a backslash, but the backslash remains in the string". Seems a bit
> pointless to me. I would've preferred the backslash to have no special
> behaviour at all. Simpler, IMHO...

not sure what you are implying here.  i understood "string quotes" in the
text you quote (which i had read) to mean \" and \', which is the
behaviour the original poster saw (and why you cannot end a string with a
slash).

however, you seem to think "string quotes" are \u escapes?  did you see:

  As a result, '\U' and '\u' escapes in raw strings are not
  treated specially.

a few paragraphs above?

also,

>>> len(r"\u0041")
6

andrew

> --
> http://mail.python.org/mailman/listinfo/python-list
>
>





More information about the Python-list mailing list