What is a classmethod for?

Dennis Peterson denpeterson at yahoo.com
Sun Jun 2 12:26:07 EDT 2002


class C:
    def foo(cls):
        print cls
    foo = classmethod(foo)

class D(C):
    pass

c = C()
d = D()
c.foo() prints __main__.C
d.foo() prints __main__.D

That's nice, but I can't think of a use for it, given that we have
inheritance and isinstance(). Can anyone enlighten me?

Thanks,
Dennis





More information about the Python-list mailing list