[Tutor] what do you use @staticmethod for?
wescpy at gmail.com
Thu Nov 20 01:29:51 CET 2008
On 11/19/08, Alan Gauld <alan.gauld at btinternet.com> wrote:
> "spir" <denis.spir at free.fr> wrote
>> I have not yet found any use for this feature.
> Which makes it very different to an instance method. instance
> methods act on instances. class methods act on the entire
> class - ie they can affect all of the instances or none.
> You don't need to use class methods(or statics) very often
> but when you do they are invaluable.
the good news is that all of these fancy features are *optional*. if
you don't know what they're useful for, that probably means you don't
need them yet, so no need to stress that you *have* to learn what they
are as you're learning the language.
at some point, you'll come across a situation where you *wished* that
Python had some feature you wanted, like a function used only in
relation to a class or its instances but don't want to define it as an
external function (@staticmethod) or to have a method where the class
object itself is passed in for you to be able to modify a class value
global to all instances (@classmethod), and to discover that features
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
More information about the Tutor