Class Methods Vs Any Other Callable
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Thu May 15 03:24:21 EDT 2008
vbgunz a écrit :
>>>> Instance methods make the most sense. A static method makes sense too
>>>> *but* I can see how a class method not only does what a static method
>>>> does but how a class method *also* gets the cls reference for free.
>>> I don't understand the last part - but I certainly agree on the "instance
>>> methods make the most sense". But *if* you want a hierarchy
>>> of "sensefulness",
>>> method > classmethod > staticmethod
>
> Sorry I quoted this earlier and meant to respond to it. What I meant
> was, might as well use a class method over a static method AND in
> doing so, cls is free.
cf Georges Sakkis point about this. 'cls is free' ? Well, not
necessarily. Your function must take the class as first argument, and so
you just can't use just any plain function as a classmethod.
More information about the Python-list
mailing list