Can __iter__ be used as a classmethod?

Greg Ewing (using news.cis.dfn.de) me at privacy.net
Tue Mar 11 05:03:34 CET 2003


Alex Martelli wrote:
> Aren't these reasons enough?  How else would you code a method that
> you can indifferently call either on any instance or on the class
> object itself?

How often do people actually *need* that functionality,
though? Smalltalkers don't seem to be bothered by the
need to know whether to call a method on a class or an
instance. Can someone provide a compelling use case
for this in Python?

> And _having_ to write a custom metaclass as the
> only way to get classmethods would be somewhat of an overkill.

What if there were some syntactic support, such as

   class C:

     def class foo(cls):
       ...

which would trigger the automatic creation of a
suitable metaclass. Would there still be a pressing
need for classmethod()-style class methods then?

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg





More information about the Python-list mailing list