[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
were
introduced into python before class methods (not by much - one
release?)
and to support backward compatibility they stayed. In practice
classmethod
will be a better choice.
IMHO at least :-)
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list