try: iterator = iter(the_element) except TypeError: # not iterable else: # iterable # for obj in iterator: # pass