Can __iter__ be used as a classmethod?
Bjorn Pettersen
BPettersen at NAREX.com
Tue Mar 4 04:47:18 EST 2003
> From: Lulu of the Lotus-Eaters [mailto:mertz at gnosis.cx]
>
> "Bjorn Pettersen" <BPettersen at NAREX.com> wrote previously:
> |I would like to be able to traverse the content of a class (not an
> |instance) using a regular for loop: "for item in MyClass:...".
>
> If you want to add methods to a *class*, you create the class using a
> custom metaclass:
Thank you very much! Could you also explain why <wink>? (e.g. why can I
make items() a classmethod but not __iter__, and how does
__metaclass__.__iter__ get called from iter(ClassIter)? -- it doesn't
show up when using dir()...)
Just doing my first meta class project since Smalltalk in the early
90's...
-- bjorn
More information about the Python-list
mailing list