I'm sure there's a good reason!

Ken Seehof kens at sightreader.com
Thu Mar 22 00:49:26 CET 2001


Does this answer your question?

>>> a = r"Am I using \"raw strings\" now?"
>>> print a
Am I using \"raw strings\" now?

If (odd) trailing backslashes were allowed, the example wouldn't
parse like that.

----- Original Message ----- 
From: "Tim Rowe" <digitig at cix.co.uk>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Wednesday, March 21, 2001 2:02 PM
Subject: I'm sure there's a good reason!


> Can any of the assembled experts explain to me why:
> print r"\hello"
> is fine, but
> print r"hello\"
> isn't? In other words, why does the backslash escape quotes in a raw 
> string? At one level I'm going to guess (without reading the spec) that 
> it's because "that's what the spec says", but why? I thought the idea of 
> raw strings was that they /didn't/ handle escapes!
> 
> TIA,
> 
> Tim
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list