Back

Explore Courses Blog Tutorials Interview Questions
+3 votes
8 views
in Python by (3.5k points)
edited by

How do I find out a name of class that created an instance of an object in Python if the function I am doing this from is the base class of which the class of the instance has been derived?

Was thinking maybe the inspect module might have helped me out here, but it doesn't seem to give me what I want. And short of parsing the __class__ member, I'm not sure how to get at this information.

2 Answers

0 votes
by (2k points)
edited by

Just use type(y).__name__ it will easily solve your issue, Here is your syntax:

>>> import itertools
>>> y = itertools.count(0)
>>> type(y).__name__
'count'

or use this if this doesn't work y.__class__.__name__

0 votes
by (106k points)

You can use the following piece of code:-

instance.__class__.__name__

You can use the following video tutorials to clear all your doubts:-

Related questions

Browse Categories

...