Here is my version of the technique put into a simple function that will test if the specified object is a descendant of the specified class name.
from inspect import getmro
def istype(obj, typename):
  return typename in [clsobj.__name__ for clsobj in getmro(obj.__class__)]
class A(object):
  pass
class B(A):
  pass
if __name__ == "__main__":
  print istype(B(), "A")
  print istype(B(), "object")
how about that:
ReplyDeleteprint isinstance(B(), B)
print isinstance(B(), A)