[Q] Type checking...
Gordon McMillan
gmcm at hypernet.com
Mon Jul 19 09:23:37 EDT 1999
Olivier Deckmyn asks:
>
> Abstract : [Q]How to check the type of an instance before(after?)
> sending it to a method...
The builtin function "isinstance".
If class A has method frobnicate(), your code will be much more
general if you do
class B:
def DoSomething(self, thing):
try:
thing.frobnicate()
except:
...
This lets your users implement the A interface without having to
actually be an A.
- Gordon
More information about the Python-list
mailing list