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
--
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)
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
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
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,
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?
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
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