is parameter an iterable?

py codecraig at gmail.com
Tue Nov 15 20:02:49 CET 2005


I have function which takes an argument.  My code needs that argument
to be an iterable (something i can loop over)...so I dont care if its a
list, tuple, etc.  So I need a way to make sure that the argument is an
iterable before using it.  I know I could do...

def foo(inputVal):
    if isinstance(inputVal, (list, tuple)):
        for val in inputVal:
            # do stuff

...however I want to cover any iterable since i just need to loop over
it.

any suggestions?




More information about the Python-list mailing list