Code Generator written in python

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Jan 13 11:26:01 EST 2010


En Wed, 13 Jan 2010 13:09:38 -0300, Arnaud Delobelle  
<arnodel at googlemail.com> escribió:

> nyoka <danshizzle at gmail.com> writes:
>
>> Can someone help me with sample python code for a code generator
>
> Sure, here are some example of self-evaluating python objects, i.e. for  
> each v
> below,
>
>        v == eval(v)
>
> I'm quite proud of the last one.

And I'm still trying to disembowel it! :)

> v = (lambda x:x%('"''""'+x+'"''""'))("""(lambda  
> x:x%%('"''""'+x+'"''""'))(%s)""")
>
> v = (lambda x:x%('r\"'+x+'\"'))(r"(lambda x:x%%('r\"'+x+'\"'))(%s)")
>
> v = (lambda x:x%`x`)('(lambda x:x%%`x`)(%s)')
>
> v = (lambda x: x+"("+`x`+")")('(lambda x: x+"("+`x`+")")')
>
> v = "\"%s\" %% ((r\"%s\",)*2)" % ((r"\"%s\" %% ((r\"%s\",)*2)",)*2)

-- 
Gabriel Genellina




More information about the Python-list mailing list