Reputation: 2859
I have a super class named as Person
and I extend this class as Employee
. I want to print the name of this extended (child) class inside the super (parent) class.
Is this possible? If so, how can I print the child class name?
Upvotes: 5
Views: 5108
Reputation: 5554
You can do this with type(self).__name__
.
type(self)
gets the actual class of self
, even if called in a base class.
All classes have a __name__
attribute which gives their name as a string.
Upvotes: 9