Python self-evaluating strings
Arnaud Delobelle
arnodel at googlemail.com
Sun Jan 27 19:07:31 EST 2008
On Jan 27, 4:14 pm, Arnaud Delobelle <arno... at googlemail.com> wrote:
[...]
> 1. Starting from the classic idea (lambda x:x%x)('lambda x:x%x') I got
> the following
> v=(lambda x:x%('"''""'+x+'"''""'))("""(lambda x:x%%('"''""'+x+'"''""'))
> (%s)""")
A bit more readable:
v1=(lambda x:x%('r\"'+x+'\"'))(r"(lambda x:x%%('r\"'+x+'\"'))(%s)")
To Dan and Boris, this is cheating:-) I particularly like Boris's
"solution", it bends the rule very nicely! Although you should get a
NameError, not a SyntaxError for python < 3.0.
--
Arnaud
More information about the Python-list
mailing list