question about True values

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Oct 28 13:15:31 CEST 2006


On Sat, 28 Oct 2006 11:42:42 +0200, Marc 'BlackJack' Rintsch wrote:

> In <pan.2006.10.28.07.45.14.198030 at REMOVE.THIS.cybersource.com.au>, Steven
> D'Aprano wrote:
> 
>> On Fri, 27 Oct 2006 11:25:09 -0700, Carl Banks wrote:
>> 
>>> Iterators do have overlapping uses with lists, but the "if a:" doesn't
>>> work for them, so it's moot.
>> 
>> Sure it works for iterators.
>> 
>>>>> it = iter([0])
>>>>> bool(it)
>> True
>>>>> it.next()
>> 0
>>>>> bool(it)
>> False
> 
> It works for *this* iterator.  By accident.

Blimey, you're right. That can't be good.

In fact, it made a certain BDFL pretty mad:

http://mail.python.org/pipermail/python-dev/2005-September/056594.html

Okay, so all iterators are intentionally *supposed* to be True, always,
even if they are exhausted. As Guido says, don't treat iterators as
containers.

Fair enough.


-- 
Steven.




More information about the Python-list mailing list