Decorators and how they relate to Python - A little insight please!
sjdevnull at yahoo.com
sjdevnull at yahoo.com
Sat Oct 21 18:16:44 EDT 2006
Jerry wrote:
> Thanks to everyone that resonded. I will have to spend some time
> reading the information that you've provided.
>
> To Fredrik, unfortunately yes. I saw the examples, but couldn't get my
> head wrapped around their purpose.
You're probably looking at the newfangled @decorator syntax.
Things were a lot clearer when decorators were called explicitly:
class foo(object):
def bar(self):
...
bar = classmethod(bar)
That makes it a lot more obvious that classmethod is simply a
higher-order function (that is, it takes a function as an argument and
returns a function).
It is equivalent to the newer:
class foo(object):
@classmethod
def bar(self):
...
More information about the Python-list
mailing list