On Tue, 2005-11-15 at 11:01 -0800, py wrote: > 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? >
You could probably get away with if hasattr(inputVal, '__getitem__') -- http://mail.python.org/mailman/listinfo/python-list