sufficiently pythonic code for testing type of function
Theerasak Photha
hanumizzle at gmail.com
Wed Oct 11 01:06:11 EDT 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):
break
else:
raise ValueError, 'object is not in %s' % types
-- Theerasak
More information about the Python-list
mailing list