Is there any way to check if object is an instance of a class? Not an instance of a concrete class, but an instance of any class.
I can check that an object is not a class, not a module, not a traceback etc., but I am interested in a simple solution.
isinstance()
is your friend here. It returns a boolean and can be used in the following ways to check types.
if isinstance(obj, (int, long, float, complex)):
print obj, "is a built-in number type"
if isinstance(obj, MyClass):
print obj, "is of type MyClass"
Hope this helps.