cls & self
Diez B. Roggisch
deets at nospam.web.de
Fri Jul 27 12:50:43 CEST 2007
> is cls & self the same thing?
> I have seen something like
> class A:
> def dosomething(cls):
> #doing something
> How is cls & self differ? How is it use?
cls and self are just names. And you most certainly haven't seen the
above, but this instead:
The decorator "classmethod" makes a method of a class a class-method.
That means that it's not invoked like this
a = A()
instead. Common usage are e.g. factory methods. And because it is a
classmethod, it gets the class passed as first argument, not the instance.
More information about the Python-list