is this a Python bug?

Fredrik Lundh effbot at
Tue Feb 15 21:47:40 CET 2000

Brian Langenberger <brian at> 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.  When I did, I got this result:
> Python 1.5.2 (#1, Sep 17 1999, 20:15:36)  [GCC egcs-2.91.66 19990314/Linux
(egcs- on linux-i386
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> r'\\\'
>   File "<stdin>", line 1
>     r'\\\'
>          ^
> SyntaxError: invalid token
> >>>
> Is this an error in the implementation or did I miss something in
> the docs?  I don't actually *need* such a string; I just found this
> while experimenting with the interpreter.

you missed something in the docs:

    "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. /.../
    Specifically, a raw string cannot end in a single
    backslash (since the backslash would escape the
    following quote character)."


More information about the Python-list mailing list