class ParentClass:
def print_child_class_name(self):
print('how to find print the child class name here')
class ChildClass1(ParentClass):
pass
class ChildClass2(ParentClass):
pass
child_1 = ChildClass1()
child_2 = ChildClass2()
child_1.print_child_class_name()
child_2.print_child_class_name()
You'd use: self.__class__.__name__
to retrieve the name of the class of the instance self
.
class ParentClass:
def print_child_class_name(self):
print(self.__class__.__name__)
class ChildClass1(ParentClass):
pass
class ChildClass2(ParentClass):
pass
child_1 = ChildClass1()
child_2 = ChildClass2()
child_1.print_child_class_name() #Prints ChildClass1
child_2.print_child_class_name() # Prints ChildClass2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With