Can __iter__ be used as a classmethod?

Bjorn Pettersen BPettersen at
Tue Mar 4 10:47:18 CET 2003

> From: Lulu of the Lotus-Eaters [mailto:mertz at] 
> "Bjorn Pettersen" <BPettersen at> 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

-- bjorn

More information about the Python-list mailing list