Getting in to metaprogramming
castironpi at gmail.com
Sat Nov 29 02:43:07 CET 2008
On Nov 27, 8:21 pm, Steven D'Aprano <st... at REMOVE-THIS-
> 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).
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
P.S. tempt: '5. Obsolete. to try or test.' http://dictionary.reference.com/browse/tempt
More information about the Python-list