[Python-3000] Iterators for dict keys, values, and items == annoying :)
Ian Bicking
ianb at colorstudy.com
Thu Mar 23 23:00:30 CET 2006
Robert Brewer wrote:
> Guido van Rossum:
>
>>>I've read and re-read Jim's message, and I'm not
>>>sure I understand it. It seems he's working in
>>>an interactive session but I'm not sure I
>>>understand the problem he has with adding list()
>>>around an expression
>
>
> Jim Fulton wrote:
>
>>It's a hassle.
>>...
>>I'd be interested to hear if other people who have experience working
>>with ZODB BTrees have been as annoyed as I've been.
>
>
> It is a hassle. I recently changed my ORM's API from returning iterators
> to lists based on similar user feedback (and I could have sworn I
> already made this comment on this issue, but I can't find it now). That
> experience hints to me that any interface that prefers iterators over
> lists is going to be resisted; builtins doubly so.
This has been my personal experience with the iterators in SQLObject as
well. The fact that an empty iterator is true tends to cause particular
problems in that case, though I notice iterkeys() acts properly in this
case; maybe part of the issue is that I'm actually using iterables
instead of iterators, where I can't actually test the truthfulness.
Another issue I have with generators (and hence iterators) is the
uselessness of repr() on them. This causes a lot of list() invocations
as well, which works with interactive testing, but fails badly with
print statements (where you have to do another run with list() around it
-- but that itself causes problems when exhausting the iterator
introduces a new bug).
--
Ian Bicking / ianb at colorstudy.com / http://blog.ianbicking.org
More information about the Python-3000
mailing list