What is a static method and when should I use one?
mahela007
6
Posting Whiz in Training
Recommended Answers
Jump to Post# staticmethod() and classmethod() # make it easier to call one class method class ClassA(object): def test(this): print this test = staticmethod(test) ClassA.test(4) # 4 class ClassB(object): @classmethod def test(self, this): print this ClassB.test(4) # 4
See:
http://www.techexperiment.com/2008/08/21/creating-static-methods-in-python/
Jump to PostA static method is one that can be called without instantiating the class
so>>> class T(object): def test(): print "HI" >>> T.test() Traceback (most recent call last): File "<pyshell#4>", line 1, in <module> T.test() TypeError: unbound method test() must be called with T instance as first …
All 6 Replies
bumsfeld
413
Nearly a Posting Virtuoso
mahela007
6
Posting Whiz in Training
lllllIllIlllI
178
Veteran Poster
Gribouillis
1,391
Programming Explorer
Team Colleague
mahela007
6
Posting Whiz in Training
mahela007
6
Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.