The str
object doesn't have an __iter__
attribute
>>> hasattr('', '__iter__')
False
so you can do a check
assert hasattr(x, '__iter__')
and this will also raise a nice AssertionError
for any other non-iterable object too.
Edit: As Tim mentions in the comments, this will only work in python 2.x, not 3.x