Re: Assigning generator expressions to ctype arrays

2011-10-29 Thread Patrick Maupin
On Oct 28, 3:24 pm, Terry Reedy tjre...@udel.edu wrote: On 10/28/2011 2:05 PM, Patrick Maupin wrote: On Oct 27, 10:23 pm, Terry Reedytjre...@udel.edu  wrote: I do not think everyone else should suffer substantial increase in space and run time to avoid surprising you. What substantial

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Steven D'Aprano
On Thu, 27 Oct 2011 17:09:34 -0700, Patrick Maupin wrote: On Oct 27, 5:31 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: From the outside, you can't tell how big a generator expression is. It has no length: I understand that. Since the array object has no way of

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Terry Reedy
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

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Patrick Maupin
On Oct 27, 10:23 pm, Terry Reedy tjre...@udel.edu wrote: I do not think everyone else should suffer substantial increase in space and run time to avoid surprising you. What substantial increase? There's already a check that winds up raising an exception. Just make it empty an iterator

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Terry Reedy
On 10/28/2011 2:05 PM, Patrick Maupin wrote: On Oct 27, 10:23 pm, Terry Reedytjre...@udel.edu wrote: I do not think everyone else should suffer substantial increase in space and run time to avoid surprising you. What substantial increase? of time and space, as I said, for the temporary

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Patrick Maupin
On Oct 28, 3:19 am, Terry Reedy tjre...@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,

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Patrick Maupin
On Oct 28, 4:51 pm, Patrick Maupin pmau...@gmail.com wrote: On Oct 28, 3:19 am, Terry Reedy tjre...@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

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Steven D'Aprano
On Fri, 28 Oct 2011 16:27:37 -0700, Patrick Maupin wrote: 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. Yes. What's your point? This fact doesn't support your proposal in the

Re: Assigning generator expressions to ctype arrays

2011-10-28 Thread Patrick Maupin
On Oct 28, 8:01 pm, Steven D'Aprano ALREADY LOSES DATA if the iterator isn't the right size and it raises an exception. Yes. What's your point? This fact doesn't support your proposal in the slightest. You earlier made the argument that If the slice has too few elements, you've just blown

Assigning generator expressions to ctype arrays

2011-10-27 Thread Patrick Maupin
Bug or misunderstanding? Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type help, copyright, credits or license for more information. x = 32 * [0] x[:] = (x for x in xrange(32)) from ctypes import c_uint x = (32 * c_uint)() x[:] = xrange(32) x[:] = (x for x in

Re: Assigning generator expressions to ctype arrays

2011-10-27 Thread Steven D'Aprano
On Thu, 27 Oct 2011 13:34:28 -0700, Patrick Maupin wrote: Bug or misunderstanding? Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) [GCC 4.5.2] on linux2 Type help, copyright, credits or license for more information. x = 32 * [0] x[:] = (x for x in xrange(32)) from ctypes import c_uint

Re: Assigning generator expressions to ctype arrays

2011-10-27 Thread Patrick Maupin
On Oct 27, 5:31 pm, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: From the outside, you can't tell how big a generator expression is. It has no length: I understand that. Since the array object has no way of telling whether the generator will have the correct size, it

Re: Assigning generator expressions to ctype arrays

2011-10-27 Thread Terry Reedy
On 10/27/2011 8:09 PM, Patrick Maupin wrote: x[:] = (x for x in xrange(32)) This translates to s.__setitem__(slice(None,None), generator_object) where 'generator_object' is completely opaque, except that it will yield 0 to infinity objects in response to next() before raising StopIteration.