When does the escape character work within raw strings?

walterbyrd walterbyrd at iname.com
Thu May 21 22:42:18 EDT 2009


I guess I am confused about when when escape characters are are
interpersonal as escape characters, and escape characters are not
treated as escape characters.

Sometimes escape characters in regular strings are treated as escape
characters, sometimes not. Same seems to go for raw strings. So how do
I know?

IMO: '\' characters in raw strings should not be given any special
meaning. That would also solve the common problem of r'c:\whatever\'
not working in python. But I digress.


To me this does not seem right. r'\n' should not equal '\n'

>>> s = 'x\nx'
>>> a = re.sub('\n', 'x', s)
>>> a
'xxx'
>>> a = re.sub(r'\n', 'x', s)
>>> a
'xxx'
>>>




More information about the Python-list mailing list