Raw strings and escaping

Jon Ribbens jon+usenet at unequivocal.co.uk
Tue Oct 3 13:17:23 CEST 2006

In article <mailman.1152.1159872720.10491.python-list at python.org>, Matthew Warren wrote:
> I would expect this to work,
> rawstring=r'some things\new things\some other things\'
> But it fails as the last backslash escapes the single quote.

String constants in Python are weird - raw strings doubly so.
In a raw string, backslashes are not special - unless followed by
a quote character, when they simultaneously escape the quote and
also insert a literal backslash.

I presume there was originally some reason for this bizarre behaviour
- it'd be interesting to know what it is/was, if anyone knows?

More information about the Python-list mailing list