What is a classmethod for?

Benno benjl at cse.unsw.edu.au
Sun Jun 2 19:30:46 EDT 2002

aahz at pythoncraft.com (Aahz) wrote in message news:<addlm6$g44$1 at panix1.panix.com>...
> In article <addgv30f4d at enews4.newsguy.com>,
> Dennis Peterson <denpeterson at yahoo.com> wrote:
> >
> >
> >That's nice, but I can't think of a use for it, given that we have
> >inheritance and isinstance(). Can anyone enlighten me?
> The point is that you can call class methods *without* creating an
> instance:
> C.foo()
> D.foo()
> This allows you to manipulate class variables through methods, rather
> than using functions or needing to create an instance.

Which is really useful if you are overriding __new__(). (Which is itself a
class method iirc).



More information about the Python-list mailing list