How to test if object is sequence, or iterable?

2006-07-22 Thread Tim N. van der Leeuw
Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). Does something like that exist? (Something which, in case of iterable, doesn't consume the first element of the iterable) Regards, --Tim --

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Bruno Desthuilliers
Tim N. van der Leeuw a écrit : Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). Does something like that exist? (Something which, in case of iterable, doesn't consume the first element of the iterable)

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Tim N. van der Leeuw
Bruno Desthuilliers wrote: Tim N. van der Leeuw a écrit : Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). Does something like that exist? (Something which, in case of iterable, doesn't consume

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Terry Reedy
Tim N. van der Leeuw [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). How about try: it = iter(possible_iterable) except TypeError: bail() Terry

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Bruno Desthuilliers wrote: Tim N. van der Leeuw a écrit : Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). Does something like that exist? (Something which, in case of iterable,

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Bruno Desthuilliers
Marc 'BlackJack' Rintsch a écrit : In [EMAIL PROTECTED], Bruno Desthuilliers wrote: Tim N. van der Leeuw a écrit : Hi, I'd like to know if there's a way to check if an object is a sequence, or an iterable. Something like issequence() or isiterable(). Does something like that exist?

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Nick Vatamaniuc
Tim, An object is iterable if it implements the iterator protocol. A good enough check to see if it does is to check for the presense of the __iter__() method. The way to do it is: hasattr(object,'__iter__') You are correct in the fact that you check if an object is iterable rather than using

Re: How to test if object is sequence, or iterable?

2006-07-22 Thread Terry Reedy
Nick Vatamaniuc [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Tim, An object is iterable if it implements the iterator protocol There are presently two iterator protocols. The old one will be likely be dropped in 3.0 (currently being discussed). . A good enough check to see