is this a Python bug?

Fredrik Lundh effbot at telia.com
Wed Feb 16 12:19:12 EST 2000


Brian Langenberger <brian at brian.cbs.umn.edu> wrote:
> : 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? :)

a Python string literal consists of an opening quote, a
sequence of escape codes and plain characters, and an
ending quote, i.e.

    open ( escape | character )* close

The "r" prefix doesn't change this; Python still parses the
string as if it were an ordinary string, but stores it differently.

in other words, both "\" and r"\" are parsed as an open quote,
followed by an escaped quote, but no closing quote.

</F>





More information about the Python-list mailing list