Python self-evaluating strings

Arnaud Delobelle arnodel at googlemail.com
Tue Jan 29 08:06:34 CET 2008


On Jan 29, 3:48 am, "Terry Reedy" <tjre... at udel.edu> wrote:
> "Arnaud Delobelle" <arno... at googlemail.com> wrote in message
>
> news:a04ca850-fe63-4b7e-abff-cdacab3bcc0f at i29g2000prf.googlegroups.com...
> | I found this:http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
>
> Exactly the one I meant.
>
> | It contains a lambda-solution similar to mine, only more concise:
>
> | (lambda x:x%`x`)('(lambda x:x%%`x`)(%s)')
>
> Being a Lisp novice, I was rather proud of that translation
>
> | I have been using python for 7 years, and it the first time ever that
> | I see the `...` construct being used!
>
> It is going away in 3.0, so the above would need revision to work with
> repr(), if indeed it will.

Here's the py3k-compliant version:

>>> k=(lambda x:x%repr(x))('(lambda x:x%%repr(x))(%s)')
>>> k == eval(k)
True

--
Arnaud



More information about the Python-list mailing list