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
1 Answer 1
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
Ignacio Vazquez-Abrams Ignacio Vazquez-Abrams
803k160 gold badges1.4k silver badges1.4k bronze badges
Comments
lang-py