sufficiently pythonic code for testing type of function

Fredrik Lundh fredrik at pythonware.com
Wed Oct 11 01:30:40 EDT 2006


Theerasak Photha wrote:

> I wrote this for someone else to take an object and list of types,
> then check if obj is one of those types, raising an error otherwise.

note that a call to your function is pretty much equivalent to

	assert isinstance(obj, types)

which has the additional advantage that you can provide a more specific 
message:

	assert isinstance(obj, types), "message"

and also disable the check once you've verified that the code actually 
does the right thing.

</F>




More information about the Python-list mailing list