escape sequences and string comparisons

Steve Holden sholden at holdenweb.com
Tue Jan 9 16:20:04 EST 2001


<jkndeja at my-deja.com> wrote in message news:93elo7$aoh$1 at nnrp1.deja.com...
> OK, my question is being purified ;-) into the following:
>
> [Quotes Python behavior]
>
> [Quotes K&R C Book]
>
> [Quotes Harbison and Steele]
>
> My question - is there a good reason that Python has moved from this
> 'traditional' effect, which seems to me to be a useful one, for
> instance in the context of my original question? Would this behaviour
> have broken something else? Shall I raise a PEP? ;-)
>
There is indeed, as the fine manual goes on to explain shortly after the
section you quote: if you make a mistake in an escape sequence, it's much
easier to spot this if the backslash isn't just silently ignored as it will
be in ANSI C.

There are two accepted ways to put backslashes in your strings.  The first
is to use the escape sequence "\\" to represente each backslash you want.
The second is to use "raw" strings, which are standard strings preceded by
an r or R. When Python processes these it passes backslashes through. In
this latter case, the character following the backslash is ALWAYS copied
literally into the string, which means that even a raw string cannot end in
a single backslash (because the single backslash will escape the quote meant
to terminate the string.

regards
 Steve





More information about the Python-list mailing list