what is wrong with that r"\"

kyosohma at gmail.com kyosohma at gmail.com
Tue Jul 3 15:37:11 CEST 2007


On Jul 3, 8:25 am, Jean-Paul Calderone <exar... at divmod.com> wrote:
> On Tue, 03 Jul 2007 06:16:43 -0700, kyoso... at gmail.com wrote:
> >On Jul 3, 7:15 am, alf <ask at me> wrote:
> >> question without words:
>
> >>  >>> r"\"
> >>    File "<stdin>", line 1
> >>      r"\"
> >>         ^
> >> SyntaxError: EOL while scanning single-quoted string
> >>  >>> r"\ "
> >> '\\ '
>
> >One slash escapes the following character, so the proper way of
> >writing it is either
>
> >r"\\" or r"\""
>
> >Seehttp://docs.python.org/ref/strings.htmlfor more information.
>
> I wonder if the OP was asking how to spell the one-length string \?
> In that case, the answer is that it can't be done using raw strings,
> but "\\" does it.  Backslash escapes aren't interpreted in raw strings,
> but you still can't end a raw string with a backslash.
>
> Jean-Paul

Very true...sometimes I need to read these weird posts 2 or 3 times.

Mike




More information about the Python-list mailing list