Can __iter__ be used as a classmethod?

Erik Max Francis max at alcyone.com
Fri Mar 14 17:12:14 EST 2003


"Phillip J. Eby" wrote:

> I think it would be better to say that staticmethod is the one that
> doesn't give any functionality.  I also think staticmethod is poorly
> named, since it does not produce a method, and it definitely doesn't
> do what a 'static method' does in Java or any other language I know
> of.

Sure it does, at least in some circumstances:

>>> class C:
...  def f(x): print "See?", x
...  f = staticmethod(f)
... 
>>> C.f(123)
See? 123
>>> c = C()
>>> c.f(123)
See? 123

The latter example wouldn't work if f (a staticmethod) weren't acting as
a method.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ There is nothing wrong with sobriety in moderation.
\__/ John Ciardi
    Physics reference / http://www.alcyone.com/max/reference/physics/
 A physics reference.




More information about the Python-list mailing list