Raw String Question

Lie Ryan lie.1296 at gmail.com
Fri Mar 13 11:16:26 EDT 2009


MRAB wrote:
> 
> In Python 3.x a backslash doesn't have a special meaning in a raw
> string, except that it can prevent a following quote from ending the
> string, but the backslash is still included. Why? How useful is that? I
> think it would've been simpler if a backslash had _no_ special effect,
> not even with a following quote. If you want a quote then either use the
> other quote character as the delimiter or use a triple-quoted raw
> string.

I think the reason is because rawstring is originally devised for 
regular expressions and in regex it is common to want to allow both 
single quote and double quote in the same pattern, like:

<(.*?) (.*?)=("|')(.*?)("|')>



More information about the Python-list mailing list