Can I get a technical explanation on the following error

Niklas Norrthon niklas.norrthon at hotmail.com
Mon May 25 11:22:11 CEST 2009


On 25 Maj, 05:29, Jim Garrison <j... at acm.org> wrote:
> And as an interesting exercise, try
>
> print r'test \'
> print r'test \\'
>
> Because of the way raw string parsing is defined, neither of these will
> pass the parser.  In fact, a raw string cannot have a backslash as
> its last character.

Tried it:
>>> r'test \'
SyntaxError: EOL while scanning string literal

>>> r'test \\'
'test \\\\'

Second one is accepted. See the language reference section 2.4.1 as of
why; http://www.python.org/doc/current/reference/lexical_analysis.html?highlight=raw%20strings#string-literals

/Niklas Norrthon



More information about the Python-list mailing list