Reading documentation for isinstance()
and looking up examples online, examples only illustrate how to use it with builtin classes like: str, int, float, long
I have code where the variable myObj.location
will either be None
if it hasn't been set yet, be an empty str
if the function fails to return a value, or if it succeeds, then the variable will hold an object of type: geopy.location.Location
To test what this object holds, I could write code like this:
isinstance(myObject.location, (type(None), str))
If False
then I know it failed to return the Location
object. If True
then it either holds None
or a str
.
Is there a way to tell it directly to test if the object is geopy.location.Location
returning True
if the test is right?
My code works with the False
test but I like the readability of being able to say True
for an object of type geopy.location.Location
that may or may not have been built for the first time at the moment of the isinstance
test.