[Tutor] classmethod, staticmethod functions (decorator related)

Alan Gauld alan.gauld at btinternet.com
Sun Sep 12 22:05:23 CEST 2010

"Huy Ton That" <huyslogic at gmail.com> wrote

> class WhatFor(object):
>    def it(cls):
>        print 'work with %s' % cls
>    it = classmethod(it)
>    def uncommon():
>        print 'I could be a global function'
>    uncommon = staticmethod(uncommon)
> But I can't seem to understand the above. Under what circumstance 
> would
> staticmethod be useful? I am just deriving that you are not passing 
> self.

I think static methjods are largely a mistake of history. ISTR They 
introduced into python before class methods (not by much - one 
and to support backward compatibility they stayed. In practice 
will be a better choice.

IMHO at least :-)

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list