[Q] Type checking...
Gordon McMillan
gmcm at hypernet.com
Mon Jul 19 09:23:37 EDT 1999
More information about the Python-list mailing list
Mon Jul 19 09:23:37 EDT 1999
- Previous message (by thread): designing question
- Next message (by thread): [Q] Type checking...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message (by thread): designing question
- Next message (by thread): [Q] Type checking...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list