Re[4]: backslashes and r-strings r"abc"
Lenard Lindstrom <[email protected]> Wed, 28 Jul 2004 21:27:09 -0700 (Pacific Daylight Time)
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <Mahogany-0.66.0-4294844217-20040728-212718.00@pop3.norton.antivirus> |
On Tue, 27 Jul 2004 11:17:29 -0700 Mark Hahn <[email protected]> wrote: > Lenard Lindstrom wrote: > > >> Mark Hahn <[email protected]>: > >> > >>> Does anyone see any reason to preserve Python's restriction on not > >>> having a backslash as the last character of a r-string? > >> > >> The reason it's there is because, even inside r-strings, backslashes > >> still escape quote characters. To remove it, you'd have to either > >> disallow quotes embedded in r-strings, or come up with some > >other way > >> of flagging them without compromising the rawness quality of > >> r-strings. > >> > >Backslashes are not removed in raw strings. So a > >backslash-quote gives you that, a backslash-quote. Hardly > >useful for including double quotes in a single quoted string > >or vice versa. > > Well, it IS useful if the quote character you need happens to follow a > backslash. :-) > > No wonder I didn't understand what "Python in a nutshell" was explaining. > It makes no sense whatsoever. What in the hell was Guido thinking? > Regular expressions. Martin Christensen mentioned only using "r" strings for regular expressions. That is where I use them too. A backslash-quote in a pattern will match a quote in a string. And two backslashes are required to match a single backslash. Thus the even number of backslashes at the end of an "r" string rule. So "r" for "regular expression" makes sense; "r" for "raw" does not. Lenard Lindstrom <[email protected]>