Assume that class MyClass
is sometimes, but not always, defined. I have a function foo(a=None)
in which argument a
can be None
, a string, or an object of MyClass
.
My question is: If MyClass
is not defined in my Python session, how can I check the type of argument a
in a fashion similar to isinstance
without getting a NameError
?
Note on duck-typing: I am deliberately limiting the function.
I'm using Python 2.6.x and Updating is not an option. A forward-compatible solution (especially for 2.7.x) is highly appreciated.