Proper Way of checking for a collections class

G

Gary Coulbourne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,186
Messages
2,570,998
Members
47,587
Latest member
JohnetteTa

Latest Threads

Top