type-checking / type() function

Fredrik Lundh fredrik at pythonware.com
Tue Aug 20 19:22:11 CEST 2002


"Ben S" wrote:

> How can I implement rudimentary type-checking in the functions where I
> need it? (Where user Python code passes parameters to my Python code,
> for example.) I figure the type() function is what I need, but I can't
> find much information on what exactly it returns, and 'InstanceType'
> isn't specific enough. Is there a way of getting the class name from an
> instance?

you probably want isinstance, and assert.

    assert isinstance(obj, SomeClass)

see docs for details.

</F>





More information about the Python-list mailing list