[Python-ideas] having a "iterable" built-in

Terry Reedy tjreedy at udel.edu
Thu Apr 30 00:20:05 CEST 2009


Tarek Ziadé wrote:
> Hello
> 
> unless I missed it, I couldn't find a built-in to check if an object
> is iterable,
> 
> so I wrote this function :
> 
> def iterable(ob):
>     try:
>         iter(ob)
>     except TypeError:
>         return False
>     return True
> 
> 
> What about having such a built-in in Python ? (with the proper
> implementation if course)

hasattr(ob, '__iter__')




More information about the Python-ideas mailing list