Using metaclasses to play with decorators.

David MacQuigg dmq at gain.com
Thu Jun 17 22:37:36 EDT 2004


On 17 Jun 2004 17:42:40 -0700, j_mckitrick at bigfoot.com (j_mckitrick)
wrote:

>You guys are WAY over my head, and I'm supposed to be a C.S. junior!  :-\
>
>Could someone give me an idea of what metaclasses and decorators _are_?

The best I have found on metaclasses is Alex Martelli's explanation
and example in Python in a Nutshell.  There is also extensive
documentation available at http://python.org/doc/newstyle.html  I have
also written a one-page explanation for engineering students in my
Python OOP chapter at http://ece.arizona.edu/~edatools/Python

Decorators are just modifiers you can add to a function definition,
ususally to modify the behavior, as in 

def func(x,y) [staticmethod]:

These are not yet in Python.  See PEP 318 for more explanationa and
examples.

-- Dave


>I think metaclasses are classes with their base methods overridden, correct?
>
>And decorators are a form of delegation, right?
>
>If so, where am I wrong?  And how do these techniques make for better code/coding?
>
>jonathon




More information about the Python-list mailing list