I could not find a good way to get the name of a class from an instance with Python on google. It’s simple (but not obvious):
str(type(var))
I could not find a good way to get the name of a class from an instance with Python on google. It’s simple (but not obvious):
str(type(var))
#1 by James Skinner on July 5, 2012 - 5:57 pm
var.__class__ will get you first the class var is an instance of.
var.__class__.__name__ will be the class’s name, var.__class__.__module__ it’s module – you can use __name__ on that as well.
There are some methods in the inspect module for doing things like getting the inheritance tree for a class if you really need it