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?

solution 1:

type(x).__name__ will give you the name of the class, which I think is what you want.

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

solution 2:

x.__class__.__name__

0 comments

Popular Posts

无觅相关文章插件,迅速提升网站流量