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

Cameron Simpson cs at zip.com.au
Thu Apr 30 08:08:16 CEST 2009

On 30Apr2009 10:57, Ben Finney <ben+python at benfinney.id.au> wrote:
| Cameron Simpson <cs at zip.com.au> writes:
| > On 29Apr2009 20:47, Tarek Ziad? <ziade.tarek at gmail.com> wrote:
| > | 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?
| If getting an iterator of an object has side effects, I'd say that
| object's implementation is buggy.
| > For example, "ob" might be a store-of-recent-messages, which empties
| > after they have been collected. Or a file() attached to a pipe.
| Neither of which should lose any items merely by getting an iterable.
| The only thing that should cause the iterable to “lose” items is
| calling its ‘next’ method, which never happens with Tarek's code above.

Oh. Sorry, my bad. You're absolutely right. I was confusing getting the
iterator with using it. Thanks!
Cameron Simpson <cs at zip.com.au> DoD#743

...if you don't get the finger several times a day [while commuting in
Boston], you're not driving correctly.  - Mark Parrenteau, DJ, WBCN Boston

More information about the Python-ideas mailing list