python3 raw strings and \u escapes

Terry Reedy tjreedy at udel.edu
Wed May 30 12:46:21 EDT 2012


On 5/30/2012 2:52 AM, rurpy at yahoo.com wrote:
> In python2, "\u" escapes are processed in raw unicode
> strings. That is, ur'\u3000' is a string of length 1
> consisting of the IDEOGRAPHIC SPACE unicode character.

That surprised me until I rechecked the fine manual and found:
"When an 'r' or 'R' prefix is present, a character following a backslash 
is included in the string without change, and all backslashes are left 
in the string."
"When an 'r' or 'R' prefix is used in conjunction with a 'u' or 'U' 
prefix, then the \uXXXX and \UXXXXXXXX escape sequences are processed 
while all other backslashes are left in the string."
When 'u' was removed in Python 3, a choice had to be made and the first 
must have seemed to be the obvious one, or perhaps the automatic one.
In 3.3, 'u' is being restored. I have inquired on pydev list whether the 
difference above should also be restored, and mentioned this thread.
-- 
Terry Jan Reedy


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /