The following Python 3.5 code:
class Base(object):
def __init__(self):
print("My type is", type(self))
class Derived(Base):
def __init__(self):
super().__init__()
print("My type is", type(self))
d = Derived()
prints:
My type is <class '__main__.Derived'>
My type is <class '__main__.Derived'>
I would like to know, inside each __init__()
, the class where the method was defined, not the deriving class. So I would get the following print:
My type is <class '__main__.Base'>
My type is <class '__main__.Derived'>