[Python-ideas] having a "iterable" built-in
Cameron Simpson
cs at zip.com.au
Wed Apr 29 23:42:15 CEST 2009
On 29Apr2009 20:47, Tarek Ziad? <ziade.tarek at gmail.com> wrote:
| 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
This is actually a bad way of doing it. Suppose using the iterator has
side effects? For example, "ob" might be a store-of-recent-messages,
which empties after they have been collected. Or a file() attached to a
pipe.
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
Morning people may be respected, but night people are feared.
- Bob Barker <Bob.Barker at MCI.Com>
More information about the Python-ideas
mailing list