[Python-Dev] Single- vs. Multi-pass iterability

David Abrahams David Abrahams" <david.abrahams@rcn.com
Fri, 12 Jul 2002 06:06:34 -0400


From: "Tim Peters" <tim.one@comcast.net>

> Note that Python uses PySequence_Fast() internally in such cases.  This
does
> whatever it takes to turn an iterable object into something that can be
> indexed at random via PySequence_Fast_GET_ITEM(fastseq, int_index).
Under
> the covers it leaves lists and tuples alone, and materializes everything
> else into a temp tuple.  I haven't felt a need for something fancier than
> that in practice; the lack of participation in this thread from other
> old-timers suggests they haven't either (piling on more protocols would
> allow to optimize some cases, but it's not clear such cases are important
> enough in Python Life to be worth the bother).

Yep, I know about PySequence_Fast(), annd we're currently using that.
However I have a bunch of numerics users who will undoubtedly be working
with some kind of array from NumPy or something -- they'll be really
unimpressed with me when PySequence_Fast() copies their huge multi-pass
sequence without individual Python objects for the elements into a tuple
with each double expressed as a separate Python float.

can-you-say-PySequence_SLOW?-ly y'rs,
dave