iso_9001_
iso_9001_

Reputation: 2859

Get child class name inside super class in Python

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

Answers (1)

luther
luther

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

Related Questions