In article <[EMAIL PROTECTED]>, Duncan Booth wrote: >> I presume there was originally some reason for this bizarre behaviour >> - it'd be interesting to know what it is/was, if anyone knows? >> > See the FAQ for the explanation: > > http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r-strings-end-with-a-backslash > > The idea is that if you use raw strings for regular expressions you can > write things like: > > pattern = r'[\'"]' > > if the raw string simply ignored the backslash altogether it would be much > harder to write regular expressions that contain both sorts of quotes.
Well, hardly *much* harder: pattern = r"""foo""" Personally, I think that raw strings behaving as they do is unexpected, unintuitive and unnecessary, but it's obviously too late to change it now anyway ;-) I think standard strings accepting backslash followed by an unexpected character is also a mistake, but again it's too late to fix now. -- http://mail.python.org/mailman/listinfo/python-list