bug ?

Fredrik Lundh fredrik at pythonware.com
Wed May 9 10:36:24 EDT 2001


Uwe Schmitt wrote:
> when i write   root=r"c:\" i get problems with the "\", but
> when "\" isnt the last character in this string, e.g.
> root=r"c:\windows", it works. is this a bug ?

did you look in the documentation:

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

    Specifically, a raw string cannot end in a single backslash
    (since the backslash would escape the following quote
    character).

or the FAQ?

    http://www.python.org/doc/FAQ.html#6.29

    Q. 6.29. Why can't raw strings (r-strings) end with a backslash?

    A. More precisely, they can't end with an odd number of back-
    slashes: the unpaired backslash at the end escapes the closing
    quote character, leaving an unterminated string.

(to look at it another way, "r" doesn't change how Python finds
the end of the string literal; it only affects how the string is stored
in memory)

Cheers /F





More information about the Python-list mailing list