Can __iter__ be used as a classmethod?

Erik Max Francis max at
Fri Mar 14 23:12:14 CET 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 /
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ There is nothing wrong with sobriety in moderation.
\__/ John Ciardi
    Physics reference /
 A physics reference.

More information about the Python-list mailing list