os.path.isfile
Erik
python at lucidity.plus.com
Sun Feb 12 19:34:27 EST 2017
On 13/02/17 00:23, Erik wrote:
>>>>>> r"hello \the" "worl\d" "\t"
>>> 'hello \\theworl\\d\t'
>>>
>>> The initial string is raw. The following string adopts that (same as the
>>> second example), but the _next_ string does not!
>
> Why is the first string token parsed as a "raw" string, the second
> string token also parsed as a "raw" string (without the 'r' prefix), but
> the third string token NOT?
>
> That's what I'm trying to point out.
OK, I get it now - because '\d' is not a valid escape sequence, then
even in a non-raw string literal, the '\' is treated as a literal
backslash character (not an escape).
So, the second string token is NOT being treated as "raw", it just looks
that way from the repr (and as you point out, a newer version of the
parser which explicitly complains about invalid escape sequences removes
that ambiguity).
Cool ;)
E.
More information about the Python-list
mailing list