metaclasses
Benjamin
musiccomposition at gmail.com
Mon Mar 3 23:01:33 EST 2008
On Mar 3, 7:12 pm, castiro... at gmail.com wrote:
> What are metaclasses?
Depends on whether you want to be confused or not. If you do, look at
this old but still head bursting essay: http://www.python.org/doc/essays/metaclasses/.
Basically, the metaclass of a (new-style) class is responsible for
creating the class. This means when Python sees
class Foo(object):
__metaclass__ = FooMeta
class FooMeta(type):
def __new__(cls, name, bases, dct):
#do something cool to the class
pass
It asks FooMeta to create the class Foo. Metaclasses always extend
type because type is the default metaclass.
More information about the Python-list
mailing list