Bad raw string handling, string ends with backslash

Anders J. Munch andersjm at dancontrol.dk
Tue May 27 05:46:36 EDT 2003


"Wolfgang" <wl at flexis.de> wrote:
> I have to do this:
> 
> xyz = r"T:\bin\bla" + "\\"
> 
[...]
> 
> why this behaviour ?

Tokenizing strings happens in two stages:
 1) Delimit the string by looking for a matching string delimiter that
    is not preceeded by an odd number of backslashes.
 2) Parse the delimited contents, interpreting backslash escapes.

Raw strings means that step 2) has been skipped.

The party line is that this is a feature, serving to make it easier to
use \" and \' in regular expressions.

- Anders







More information about the Python-list mailing list