Re: backslashes and r-strings r"abc"

Martin Christensen <[email protected]> Mon, 26 Jul 2004 23:45:01 +0200
Newsgroups gmane.comp.lang.prothon.user
Message-ID <[email protected]>
>>>>> "Mark" == Mark Hahn <[email protected]> writes:
Mark> Both the Python warts list and the Gotchas list complain about
Mark> the confusion of the r"abc" strings and the need for them.  The
Mark> gotchas list even calls the backslash escape character itself a
Mark> "gotcha".
Mark> Does everyone agree with this?  Does anyone have any idea how to
Mark> fix these?  What could possible replace the backslash esc char?

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.

Martin

-- 
Homepage:       http://www.cs.auc.dk/~factotum/
GPG public key: http://www.cs.auc.dk/~factotum/gpgkey.txt
signature.asc (application/pgp-signature, 196 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iEYEABECAAYFAkEFe18ACgkQYu1fMmOQldUeagCeNIc6umN/d//a/Cw3fKfG84LN
1XYAn00QOG9TPScRxaTat7We9PDifdMj
=r92+
-----END PGP SIGNATURE-----