is this a Python bug?

Gerrit Holl gerrit.holl at pobox.com
Wed Feb 16 10:22:57 EST 2000


Brian Langenberger wrote on 950706753:
> piet at cs.uu.nl wrote:
> :>>>>> Moshe Zadka <moshez at math.huji.ac.il> (MZ) writes:
> 
> : MZ> On 15 Feb 2000, Brian Langenberger wrote:
> :>> R is supposed to work to give raw strings with the backslashes stored
> :>> as backslashes.  I've never had a problem until I tried making a
> :>> string with nothing but backslashes.  
> 
> : MZ> Raw strings cannot end with a backslash. 
> 
> : They can. But only with an even number of them.
> 
> I'm assuming there's some clever and important reason for this.
> But for the life of me I can't figure out what it is.
> Could someone enlighten me as to the reason? :)

http://www.python.org/doc/current/ref/strings.html

   When an `r' or `R' prefix is present, backslashes are still used to
   quote the following character, but all backslashes are left in the
   string. For example, the string literal r"\n" consists of two
   characters: a backslash and a lowercase `n'. String quotes can be
   escaped with a backslash, but the backslash remains in the string; for
   example, r"\"" is a valid string literal consisting of two characters:
   a backslash and a double quote; r"\" is not a value string literal
   (even a raw string cannot end in an odd number of backslashes).
   Specifically, a raw string cannot end in a single backslash (since the
   backslash would escape the following quote character).

regards,
Gerrit.

-- 
Homepage: http://www.nl.linux.org/~gerrit
-----BEGIN GEEK CODE BLOCK----- http://www.geekcode.com
Version: 3.12
GCS dpu s-:-- a14 C++++>$ UL++ P--- L+++ E--- W++ N o? K? w--- !O
!M !V PS+ PE? Y? PGP-- t- 5? X? R- tv- b+(++) DI D+ G++ !e !r !y
-----END GEEK CODE BLOCK----- moc.edockeeg.www//:ptth




More information about the Python-list mailing list