Assigning generator expressions to ctype arrays

Patrick Maupin pmaupin at gmail.com
Fri Oct 28 19:27:37 EDT 2011


On Oct 28, 4:51 pm, Patrick Maupin <pmau... at gmail.com> wrote:
> 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

And, BTW, the example you give of, e.g.

a,b,c = (some generator expression)

ALREADY LOSES DATA if the iterator isn't the right size and it raises
an exception.

It doesn't overwrite a or b or c, but you're deluding yourself if you
think that means it hasn't altered the system state.



More information about the Python-list mailing list