Getting in to metaprogramming

Aaron Brady castironpi at gmail.com
Fri Nov 28 20:43:07 EST 2008


On Nov 27, 8:21 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
snip
> body = 'L.append(None)\n'
> make_file('dumb.py', 'Create a big list the dumb way.',
>     'L = []\n', body*numitems)
> make_file('smart.py', 'Create a big list the smart way.',
>     '', 'L = [None]*%d\n' % numitems)
>
> At this point, I have two source files which I can do anything I like
> with. It would have been a real pain to have written the first one by
> hand, even with a clever editor. I can post-process them, run them
> through other tools, even open them up in an editor and manipulate them
> by hand (although that defeats the purpose of metaprogramming).
snip

I tempt that one's metaprogram is in a metalanguage, and if it's
generating two programs, it has twice the power of the language it's
in, giving it a leverage of two units.

I feel like I always do that, manipulate the metaprogram output by
hand.  I forget my use cases though, except for one that did low-level
structure handling.

P.S.  tempt: '5. Obsolete. to try or test.' http://dictionary.reference.com/browse/tempt



More information about the Python-list mailing list