[Tutor] static methods and class methods
wescpy at gmail.com
Fri Jun 13 08:10:30 CEST 2008
[static methods, class methods]
> Both of these are rarely used; I don't think I have ever written a
> class method in live code. I have used staticmethods as a convenient
> way to put a function into a class namespace.
this is someone out of the flow of the current thread now, but i
forgot to mention in my previous post that, like kent, i too, have not
used either of these much in practice on the past 11yrs of full-time
class methods: the only time i've ever done a class method is when
subclassing an immutable type, i.e., __new__() is a cls method, but
that was for the book. i've never done one in practice.
static methods: may have done 1 or 2 since they came out in 2.2, but
in reality, if general code, they stay as global functions. if i
really "want a function defined in a class definition, i may make one.
but in practice, i often find that the functions that are most
suitable as static methods end up being just *inner* functions defined
inside a (regular) method.
just my $0.02,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
More information about the Tutor