1

I use static method in Python, like this:

class A(object):
 @staticmethod
 def sfun():
 print "this is statice method"
class AA(A):
 @staticmethod
 def sfun():
 print "this is statice method"

And I want to get type of class (A or AA) in sfun. How can I do it?

Fred Foo
365k80 gold badges765 silver badges851 bronze badges
asked Jun 24, 2013 at 9:52

1 Answer 1

5

You can't. But if you use classmethod instead then the class will be passed as the first argument to the method.

class A(object):
 @classmethod
 def cfun(cls):
 print 'I am in %r' % (cls,)
class AA(A):
 pass
answered Jun 24, 2013 at 9:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.