<s>[INST] In Python, how do I determine if an object is iterable? Is there a method like isiterable? The only solution I have found so far is to call
hasattr(myObj, '__iter__')

But I am not sure how fool-proof this is.
 [/INST] 
Checking for __iter__ works on sequence types, but it would fail on e.g. strings. I would like to know the right answer too, until then, here is one possibility (which would work on strings, too):
try:
    some_object_iterator = iter(some_object)
except TypeError, te:
    print some_object, 'is not iterable'

The iter built-in checks for the __iter__ method or in the case of strings the __getitem__ method. To check if an object is "list like" and not "string like" then the key is the attributes __getitem__ and __iter__:

 In [9]: hasattr([1,2,3,4], '__iter__')
 Out[9]: True
 In [11]: hasattr((1,2,3,4), '__iter__')
 Out[11]: True
 In [12]: hasattr(u"hello", '__iter__')
 Out[12]: False
 In [14]: hasattr(u"hello", '__getitem__')
 Out[14]: True


Another general pythonic approach is to assume an iterable, then fail gracefully if it does not work on the given object. The Python glossary:

Pythonic programming style that determines an object's type by inspection of its method or attribute signature rather than by explicit relationship to some type object ("If it looks like a duck and quacks like a duck, it must be a duck.") By emphasizing interfaces rather than specific types, well-designed code improves its flexibility by allowing polymorphic substitution. Duck-typing avoids tests using type() or isinstance(). Instead, it typically employs the EAFP (Easier to Ask Forgiveness than Permission) style of programming.
...
try:
   _ = (e for e in my_object)
except TypeError:
   print my_object, 'is not iterable'


The collections module provides some abstract base classes, which allow to ask classes or instances if they provide particular functionality, for example:
import collections

if isinstance(e, collections.Iterable):
    # e is iterable


 </s>