[Python-3000] Raw strings containing \u or \U
Steven Bethard
steven.bethard at gmail.com
Wed May 16 18:55:57 CEST 2007
On 5/16/07, Guido van Rossum <guido at python.org> wrote:
> Walter Doerwald, in private mail, reminded me of a third use case for
> raw strings: docstrings containing example code using backslashes.
> Here it really seems wrong to interpolate \u and \U.
>
> So this is swaying me towards changing this behavior: r"\u1234" will
> be a string of length 6, and r"\U00012345" one of length 10.
+1 for making raw strings truly raw (where backslashes don't escape
anything) and teaching the re module about the necessary escapes (\u,
\n, \r, etc.).
> I'm still on the fence about the trailing backslash; I personally
> prefer to write Windows paths using regular strings and doubled
> backslashes.
+1 for no escaping of quotes in raw strings. Python provides so many
different ways to quote a string, the cases in which you can't just
switch to another quoting style are vanishingly small. Examples from
the stdlib and their translations::
'\'' --> "'"
'("|\')' --> '''("|')'''
'Can\'t stat' --> "Can't stat"
'(\'[^\']*\'|"[^"]*")?' --> '''('[^']*'|"[^"]*")?'''
Note that allowing trailing backslashes could also clean up stuff in
modules like ntpath::
path[-1] in "/\\" --> path[-1] in r"/\"
firstTwo == '\\\\' --> firstTwo == r'\\'
STeVe
--
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
--- Bucky Katt, Get Fuzzy
More information about the Python-3000
mailing list