Hi!
I have a method that accepts a parameter that can be of several types, and has to do one thing or other depending on the type, but if I check the type of said parameter, I don't get the 'real' type, I always get <type 'instance'>
, and that is messing up with my comparisons.
I have something like:
from classes import Class1
from classes import Class2
# Both classes are declared in the same file.
# I don't know if that can be a problem #
# ... #
def foo(parameter)
if (type(parameter) == type(Class1()):
# ... #
elif (type(parameter) == type(Class2()):
# ... #
And as type(parameter)
returns <type 'instance'>
and type(Class1())
is <type 'instance'>
as well, it turns out that even if the parameter is an instance of Class2, it is going into the first comparison...
By the way, str(parameter.__class__)
properly shows classes.Class1
. I guess I could always use that, but I would like to understand what's going on... I have made tenths of comparisons like this and all them worked properly...
Thank you!! :)