Polymorphic instance checking in Python

lss at excosoft.se lss at excosoft.se
Wed Mar 29 06:12:37 EST 2000


How is polymorphic type checking accomplished in Python? For example:
class Super: pass
class Sub(Super): pass
i = Sub()
How can I perform a test on 'i' to see if it is in fact an instance of
the Sub or Super classes (which should be true in both cases since Sub
is a subclass of Super)? One could expect the Python 'is' operator
would do that but it only returns true if both operands reference the
very same object. It would of course be possible to manually check an
instance for all the attributes that a class declares but that seems
like an unnecessary hassle. So what's the trick?
Thankful for any assistance,
Ludvig Svenonius


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list