On Thu, 26 Jul 2007 15:02:39 +0000, Neil Cerutti wrote: > Based on the discussions in this thread (thanks all for your > thoughts), I'm settling for: > > def is_iterable(obj): > try: > iter(obj).next() > return True > except TypeError: > return False > except KeyError: > return False > > The call to iter will fail for objects that don't support the > iterator protocol, and the call to next will fail for a > (hopefully large) subset of the objects that don't support the > sequence protocol.
And the `next()` consumes an element if `obj` is not "re-iterable". Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list