Getting in to metaprogramming

Terry Reedy tjreedy at udel.edu
Wed Nov 26 14:36:40 EST 2008


Hendrik van Rooyen wrote:

> I am using the term in the restricted sense of Python writing Python source.
> 
> Given that, can anybody think of an example that you could not do with 
> a class?  (excepting the "stored procedure" aspect)

I am not sure I understand your question.

def iterize(recursive_function_text):
     <code to parse input and fill a template>
     return equivalent_iterative_function_text

where input and output are both Python code.  If one were to implement 
this by compiling the input to AST form and then walking the tree, the 
AST node classes would be involved, but I would scarely say the 
translation was done by the classes, as opposed to functions which might 
or might not be attacked to a class as methods.

tjr




More information about the Python-list mailing list