[Q] Type checking...

Fredrik Lundh fredrik at pythonware.com
Mon Jul 19 08:03:03 EDT 1999


Olivier Deckmyn <olivier.deckmyn at mail.dotcom.fr> wrote:
> Abstract : [Q]How to check the type of an instance before(after?) sending it
> to a method...
> 
> Here is my source :
> 
> class ClassA
> ...
> 
> 
> class ClassB :
>    def myMethod(self, anInstance)
> ...
>
> and myMethod expects that anInstance is a ClassA !
> How can I force my user to send only instances of this
> class (or subclasses)?

assert isinstance(anInstance, ClassA)

</F>





More information about the Python-list mailing list