[Q] Type checking...

Adrian Eyre a.eyre at optichrome.com
Mon Jul 19 08:39:43 EDT 1999


> class ClassA
> ...
> 
> 
> class ClassB :
>    def myMethod(self, anInstance)
         if anInstance.__class__ != ClassA:
              raise "Oh no!"

This won't work for other classes derived from ClassA, however.
To do that, check out:

anInstance.__class__.__bases__

There may also be some cunning library hack to do this automatically.





More information about the Python-list mailing list