Metaclasses and class variables

Jan-Ole Esleben esleben at gmail.com
Thu Aug 4 15:46:10 CEST 2005


I thought __new__ was called upon construction of the _class_ object
that "Meta" is the type of. Then it would be available at the time of
the definition of my class. Or am I mistaken?

Ole

2005/8/4, Christopher Subich <spam.csubich+block at block.subich.spam.com>:
> Jan-Ole Esleben wrote:
> > class Meta(type):
> >   def __new__(cls, name, bases, d):
> >     d['classvar'] = []
> >     return type.__new__(cls, name, bases, d)
> 
> The problem is that __new__ is called upon object construction, not
> class definition, but you're trying to set the class variables at
> definition-time.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list