RE: backslashes and r-strings r"abc"

"Mark Hahn" <[email protected]> Mon, 26 Jul 2004 15:10:54 -0700
Newsgroups gmane.comp.lang.prothon.user
Message-ID <000901c4735d$6b9a65d0$0b01a8c0@mark>
Martin Christensen wrote:

>Backslash escaping is widely used, and it'd be gotcha-ish to 
>not use it as an escape character, if you ask me. I only ever 
>use raw (r'abc') strings for regular expressions, but for 
>those, they increase legibility quite a bit, I think.
>
>As I see it, the best alternative to the usual way of handling 
>escape characters is for Strings to have a 'process escape 
>characters' method that would... well, treat escape characters 
>like escape characters. I'm not certain how clear that was, so 
>here's an example:
>
>O>> 'a\tb\nc'
>a\tb\nc
>O>> 'a\tb\nc'.processEscapeCharacters()
>a       b
>c
>
>Personally I'm in favour of preserving escape characters by 
>default, if for no other reason than consistency with just 
>about every other langauge around. If escape characters are a 
>Python gotcha, then Python is not the sole perpetrator. as for 
>r'abc' being a gotcha... I don't know, really. How often is 
>that notation used outside of regular expressions? For the 
>longest time, I even thought that it was specific _to_ regular 
>expressions. :o) I don't mind either, but my opinions on the 
>subject aren't overly strong.

One thing that bothers me about Python's r-strings is that they are supposed
to pass backslashes but they throw an exception if you have a backslash as
the last character.  This makes them useless in one place I've always wanted
to use them:

	r"c:\windows directory\"  # throws Python exception

So maybe Prothon could at least fix that problem.  Does anyone see any
reason to preserve Python's restriction on not having a backslash as the
last character of a r-string?