[Python-3000] Builtin iterator type

Nick Coghlan ncoghlan at gmail.com
Sun Nov 19 07:26:39 CET 2006


Guido van Rossum wrote:
> On 11/18/06, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> (Although I will point out
>> that most  protocols for things like len() *do* involve checks for 
>> special
>> methods by name, and the check for iterability is typically a 
>> non-destructive
>> call to iter(x), rather than a destructive one to x.next()).
> 
> Ouch?! I would never check for iterability explicitly. I would just
> require it, as Greg Ewing says. iter() could be fairly expensive,
> depending on what is being iterated over.

I didn't mean to imply that the call to iter() couldn't be an implicit one in 
a for loop/genexp/listcomp/itertool. As you say, the need to check explicitly 
is rare.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list