sufficiently pythonic code for testing type of function
hanumizzle at gmail.com
Wed Oct 11 07:06:11 CEST 2006
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.
Is it enough to rely on side effects or absence thereof, or should I
put return True in here somewhere?
def test_obj_type(obj, types):
for type in types:
if isinstance(obj, type):
raise ValueError, 'object is not in %s' % types
More information about the Python-list