Re[2]: backslashes and r-strings r"abc"

Lenard Lindstrom <[email protected]> Mon, 26 Jul 2004 20:07:18 -0700 (Pacific Daylight Time)
Newsgroups gmane.comp.lang.prothon.user
Message-ID <Mahogany-0.66.0-4294505119-20040726-201238.00@pop3.norton.antivirus>
On Mon, 26 Jul 2004 15:10:54 -0700 Mark Hahn <[email protected]> wrote:

> 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?
>
Go ahead. Backslash for line continuation in a raw string is broken for both
Prothon and Python anyways:

Python 2.4a1 (#54, Jul  8 2004, 11:30:13) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> r"abc\
... def"
'abc\\\ndef'

Prothon 0.1 Interactive Console, Build 742, Jul 15 2004 (Ctrl-D to exit)
O>> r"abc\
... def"
Lexical error: unterminated quote string

By the way, what happened to string literal concatenation? I thought it was
on the todo list.

Prothon 0.1 Interactive Console, Build 742, Jul 15 2004 (Ctrl-D to exit)
O>> print("abc" "def")

Parse Error: expecting `')'' or `',''
--- col: 18

Uncaught exception:
Parse Error.

String literal concatenation replaced almost all uses of line continuation within
strings unnecessary. The only use I have found for line continuation is at the start
of triple-quoted strings.

print("""\
The following is arranged
as to how it will appear.
""")

Lenard Lindstrom
<[email protected]>