newbie-question: difference between classmethod and staticmethod in Python2.2
Gonçalo Rodrigues
op73418 at mail.telepac.pt
Wed Sep 4 10:42:08 EDT 2002
On Wed, 04 Sep 2002 16:33:18 +0200, "T. Kaufmann" <merman at snafu.de>
wrote:
>Hi there,
>
>can anybody explain the difference between 'staticmethod' and 'classmethod' in a simple way in
>Python2.2?
Morally, a static method is just a function as a class attribute, while
a class method is a method that is associated with the class, receiving
it implicitly as the first argument (as opposed to intance methods that
receive the instance as the first argument).
class methods are usually used as factory methods (creating and
returning instances of the class) as for static methods I have never
found much use to them since whatever functionality they provide is best
kept at module level. Someone else might have use cases for them.
>
>When should I use staticmethod or classmethod in classes?
>
>I thought a staticmethod is a classmethod like in C++/ Java?
>
>Thanks for help.
>
>o-o
>
>Thomas
Hope this helps somehow, if it was not sufficiently clear, just holler.
Gonçalo Rodrigues
More information about the Python-list
mailing list