Assigning generator expressions to ctype arrays

Patrick Maupin pmaupin at gmail.com
Fri Oct 28 17:51:19 EDT 2011


On Oct 28, 3:19 am, Terry Reedy <tjre... at udel.edu> wrote:
> On 10/28/2011 3:21 AM, Steven D'Aprano wrote:
>
> > If the slice has too few elements, you've just blown away the entire
> > iterator for no good reason.
> > If the slice is the right length, but the iterator doesn't next raise
> > StopIteration, you've just thrown away one perfectly good value. Hope it
> > wasn't something important.
>
> You have also over-written values that should be set back to what they
> were, before the exception is raised, which is why I said the test needs
> to be done with a temporary array.
>

Sometimes when exceptions happen, data is lost. You both make a big
deal out of simultaneously (a) not placing burden on the normal case
and (b) defining the normal case by way of what happens during an
exception.  Iterators are powerful and efficient, and ctypes are
powerful and efficient, and the only reason you've managed to give why
I shouldn't be able to fill a ctype array slice from an iterator is
that, IF I SCREW UP and the iterator doesn't produce the right amount
of data, I will have lost some data.

Regards,
Pat



More information about the Python-list mailing list