[Python-3000] Builtin iterator type
Guido van Rossum
guido at python.org
Sun Nov 19 05:13:13 CET 2006
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.
Maybe this is unique to iterators and iterators are a bad example? I
don't feel as strongly about this when testing e.g. for string-ness,
file-ness or list-ness. While I tend to dislike those tests too, they
are sometimes inevitable when we want to overload an API. Especially
file/string is often overloaded, and I see no big problem with this (I
do dislike overloading list/dict, or string/list-of-strings).
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list