[Tutor] what is @classmethod and @staticmethod ??
Kent Johnson
kent37 at tds.net
Sun Mar 23 23:26:26 CET 2008
maser wrote:
> Thanks, Andreas. Why do we need to use classmethod/
> staticmethod and where do we need to use them ?
I use staticmethods as a convenience to put related functions in the
namespace of a class. Perhaps foo.py contains class Foo with
staticmethod bar(). In client code I can say
from foo import Foo
Foo.bar()
If bar was a module method it would be
from foo import Foo, bar
bar()
I prefer the former in cases where bar is related to Foo.
Kent
More information about the Tutor
mailing list