Using metaclasses to play with decorators.
David MacQuigg
dmq at gain.com
Tue Jun 22 20:19:32 EDT 2004
On Sun, 20 Jun 2004 14:48:23 -0400, "Colin J. Williams"
<cjw at sympatico.ca> wrote:
>I have yet to wrap my mind around decorators.
Decorators are very simple. They are just a way to provide different
forms of methods, without introducing a new keyword, or some other
more awkward syntax.
Say you wanted to define a method that didn't have 'self' as its first
argument. You could add a new keyword to the language:
noself methodA(x,y):
return x + y
Or you could add a "decorator" to the existing syntax:
def methodA(x,y) [noself]:
return x + y
Change 'noself' to 'staticmethod' and you have one of the current
proposals in PEP318.
Don't get distracted by 'staticmethod' and other mumbo-jumbo
terminology, and you should have no problem with decorators.
-- Dave
More information about the Python-list
mailing list