Can __iter__ be used as a classmethod?

Thomas Heller theller at python.net
Tue Mar 4 11:14:47 EST 2003


> > Is it possible to add (class) methods to class objects by defining them in
> > a custom metaclass, or is the metaclass used only to lookup special
> > methods (__iter__, etc.) for operations executed on class objects? Since I
> 
> Just as any instance "inherits" attributes from its class, so does any class
> "inherit" attributes from its metaclass -- there is no difference between
> the two cases, nor between callable and non-callable attributes.

It should be noted that this (since it also works in Python extensions
in C) can be used to create classmethods in extensions in a way
compatible with 2.2 and 2.3.  Python 2.2 does not have the METH_CLASS
flag!

Thomas




More information about the Python-list mailing list