Can __iter__ be used as a classmethod?

Greg Ewing (using me at
Tue Mar 11 04:54:53 CET 2003

Michele Simionato wrote:
> In order to retrieve 'mm' I need to invoke dir(M): this is slightly
> inconsistent because usually when 'dir' is invoked on an instance, it
> automatically retrieves the methods of its class, therefore I would
> expect that invoked on a class it would retrieve the methods of its
> metaclass.

The reasoning here is probably that when someone
does dir(C), they want to know what operations are
supported by *instances* of C, not C itself.
It makes sense when you think about it that way.

This is just another one of the ambiguitities
caused by Python lumping together class attributes
and instance methods in the same dict.

Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand

More information about the Python-list mailing list