
April 29, 2009
9:02 p.m.
Tarek Ziadé a écrit :
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)
Regards Tarek
Well, I guess the new abilities of abstract base classes and stuffs, in 2.6, allow this : http://docs.python.org/library/collections.html You should call something like isinstance(ovj, Iterable), which is less cute than isiterable(obj), but far more flexible ^^ Regards, Pascal