Proper Way of checking for a collections class

Gary Coulbourne bear at bears.org
Thu Apr 22 13:23:00 EDT 2004


Howdy,

I've been trying to find a good idiom for testing if the input to a
function is one of the collections classes... the best I could do is this:

if hasattr(thing_to_test, '__iter__'):
    ...

Is this right?  Or, is there a better way besides a cascade of type()
tests?

Thanks!

Peace,
Gary




More information about the Python-list mailing list