class A:
def __init__(self):
pass
class B(A):
pass
class C(A):
def __init__(self):
pass
print(hasattr(B, '__init__')) # True
print(hasattr(C, '__init__')) # True
How to check if derived class has its own __init__
defined in Python? In the code above, only C has an __init__
definition, but B also has an __init__
attribute by inheritance. Is there a way to distinguish them?