Wishlist item: itertools.flatten
Leif K-Brooks
eurleif at ecritters.biz
Mon Mar 14 06:50:35 EST 2005
Michael Spencer wrote:
> if hasattr(item,"__iter__"): # Avoids iterating over strings
That's probably the cleanest way to avoid strings, but it's
unfortunately not a good idea IMHO. Many objects (IndexedCatalog's
Result objects are what I'm concerned about, but there are undoubtedly
others) still rely entirely on the old-style sequence iteration protocol
even though they're proper containers, so checking for __iter__ wouldn't
work on them. Explicitly doing isinstance(item, basestring) is probably
the best option until older objects move to the new iteration protocol.
More information about the Python-list
mailing list