"Peter Otten" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> You are in for a surprise here:

You got that right!

> >>> def empty():
> ...     for item in []:
> ...             yield item
> ...
> >>> bool(empty())
> True

Ouch.

> >>> bool(iter([]))
> True # python 2.3 and probably 2.5
>
> >>> bool(iter([]))
> False # python 2.4

Double ouch.
I was relying on Python 2.4 behavior.
What is the reasoning behind the changes?
(Can you offer a URL to a discussion?)

So, is the only way to test for an empty iterable
to see if it can generate an item?  I found this:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413614
Seems like a reason to rely on sequences ...

Thanks,
Alan Isaac


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to