0

I am trying to figure out the best and/or most elegant way to check if a variable is instance of any class except built-in types like int, float, tuple, dict, list, etc., that is why I cannot do something like:

>>> hasattr(some_var, '__class__')

Currently, what I am doing is the following:

>>> class DummyClass(object):
...     pass
... 
>>> my_var = DummyClass()
>>> 'class' in str(type(my_var))
True
>>> 'class' in str(type([]))
False
>>> 'class' in str(type(3.43))
False

Because it works with built-in types (returns False), but I would like to know if there is a better way to do this.

XNor
  • 638
  • 3
  • 8
  • 27

0 Answers0