A bug for raw string literals in Py3k?

Yingjie Lan lanyjie at yahoo.com
Mon Nov 1 00:44:47 EDT 2010


> According to msg56377, the behaviour is "optimal" for regular
> expressions. Well, I use regular expressions a lot, and I
> still think it's a nuisance!

Thanks for bringing that up.

Using an otherwise 'dead' backlash to escape quotes 
in raw strings seems like the black magic of 
necromancy to me. :)

To include quotes in a string, there are a couple of
known choices: If you need single quotes in the string, 
start the literal by a double-quote, and vice versa.
In case you need both, you can use a long string:

>>> r''''ab\c"'''

Note that when the last character is also a quote, we can
use the other type of quote three times to delimit the 
long string. Of course, there are still some corner cases:

1. when we need three consecutive single quotes AND three 
   consecutive double quotes in the string.

2. When the last is a single quote, and we also need 
   three consecutive double-quotes in the string, 
   or the other way around.

Then we can abandon the raw string literal, or use 
concatenation of string literals wisely to get it done.

But in total, I still would vote against the nacromancy.

Yingjie


      



More information about the Python-list mailing list