InstanceType tests in Python-3.0

Robin Becker robin at reportlab.com
Thu Feb 14 10:26:08 EST 2008


I'm in the process of porting some code. I have 2.x code that looks like this

t = type(e)
if t==InstanceType:
    return f0(e)
elif t in (float,int):
    return f1(e)
else:
    return str(e)

In python 3.0 everything has been unified and people say use attributes to tell 
what should be done in such a branch. However, this is the real world and this 
code is fairly complex. Originally we had a distinction between user defined 
class instances and those of the builtins like float, int, str etc etc. Is there 
any way for me to tell if an object is an instance of a used defined class which 
can then be tested further perhaps?
-- 
Robin Becker




More information about the Python-list mailing list