Descriptors and decorators
bruno.desthuilliers at gmail.com
bruno.desthuilliers at gmail.com
Tue Oct 26 04:28:46 EDT 2010
On 25 oct, 17:18, Joost Molenaar <j.j.molen... at gmail.com> wrote:
> Thanks, Bruno.
> Your python-wiki page and walk-through for the Decorator code make it
> clear. I now finally understand that methods are in fact ordinary
> functions at the time the class is created, and that the descriptor
> protocol turns them into bound or unbound methods when they're
> accessed as attributes:
(snip)
> Cheers! Now I will try to wrap my brain around metaclasses and coroutines. ;-)
Metaclasses are nothing special, really. Python classes are plain
objects and you can as well instanciate a class directly - the "class"
statement being mostly syntactic sugar:
def func(obj, x):
obj.x = x
NewClass = type("NewClass", (object,), {'__init__':func, 'foo':lambda
z: z.x + 2})
So in the end, a metaclass is just another plain class, that is used
to instanciate class objects.
More information about the Python-list
mailing list