I want to create a function that can check if the passed arg is an Exception or one of its subclasses. As an example, I would like the the second is_exception function call to return True as well.
def is_exception(obj):
return type(obj) == Exception
print is_exception(Exception('asdf')) => True
print is_exception(EOFError('asdf')) => False
thanks!
You can use issubclass:
The signature is “issubclass(A,B)” which will return True if A is a subclass of B, or “issubclass(A,(B1,B2…))” which will return True if A is a subclass of any of B1,B2 etc.