Critique of first python code

Matthew Marshall matthew at matthewmarshall.org
Sun Feb 17 10:17:57 EST 2008


Dan Bishop wrote:
> I will say, however, that hasattr(item, '__iter__') isn't a perfect
> way of checking whether an object is iterable: Objects that just
> define __getitem__ are iterable too (e.g., UserList).

Speaking of which, what *is* the best way to check if an object is 
iterable?

I always wrap iter(item) in a try/except block, but is there an
isiterable() function somewhere?

MWM



More information about the Python-list mailing list