Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15082

Re: Assigning generator expressions to ctype arrays

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Assigning generator expressions to ctype arrays
Date 2011-10-27 23:23 -0400
References <32ee8e3e-4d42-4d2e-bdc7-087970c2736e@hv4g2000vbb.googlegroups.com> <4ea9dbd0$0$29968$c3e8da3$5496439d@news.astraweb.com> <43aea5ad-bc9f-4e82-a9d5-74a06553a2ad@q16g2000yqn.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.2271.1319772206.27778.python-list@python.org> (permalink)

Show all headers | View raw


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.

Given that a cytpe_array is a *fixed-length* array, *unlike* Python's 
extensible lists and arrays, failure is a possibility due to mis-matched 
lengths. So ctype_array can either look first, as it does, by calling 
len(value_object), or leap first and create a temporary array, see if it 
fills up exactly right, and if it does, copy it over.

> I know how to work around the issue.  I'm not sure I should have to.

I do not think everyone else should suffer substantial increase in space 
and run time to avoid surprising you.

> It violates the principle of least surprise

for ctypes to do what is most efficient in 99.9% of uses?

> for the ctypes array to
> not be able to interoperate with the iterator protocol in this
> fashion.

It could, but at some cost. Remember, people use ctypes for efficiency, 
so the temp array path would have to be conditional. When you have a 
patch, open a feature request on the tracker.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Assigning generator expressions to ctype arrays Patrick Maupin <pmaupin@gmail.com> - 2011-10-27 13:34 -0700
  Re: Assigning generator expressions to ctype arrays Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-10-27 22:31 +0000
    Re: Assigning generator expressions to ctype arrays Patrick Maupin <pmaupin@gmail.com> - 2011-10-27 17:09 -0700
      Re: Assigning generator expressions to ctype arrays Terry Reedy <tjreedy@udel.edu> - 2011-10-27 23:23 -0400
        Re: Assigning generator expressions to ctype arrays Patrick Maupin <pmaupin@gmail.com> - 2011-10-28 11:05 -0700
          Re: Assigning generator expressions to ctype arrays Terry Reedy <tjreedy@udel.edu> - 2011-10-28 16:24 -0400
            Re: Assigning generator expressions to ctype arrays Patrick Maupin <pmaupin@gmail.com> - 2011-10-29 07:43 -0700
      Re: Assigning generator expressions to ctype arrays Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-10-28 07:21 +0000
        Re: Assigning generator expressions to ctype arrays Terry Reedy <tjreedy@udel.edu> - 2011-10-28 04:19 -0400
          Re: Assigning generator expressions to ctype arrays Patrick Maupin <pmaupin@gmail.com> - 2011-10-28 14:51 -0700
            Re: Assigning generator expressions to ctype arrays Patrick Maupin <pmaupin@gmail.com> - 2011-10-28 16:27 -0700
              Re: Assigning generator expressions to ctype arrays Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-10-29 01:01 +0000
                Re: Assigning generator expressions to ctype arrays Patrick Maupin <pmaupin@gmail.com> - 2011-10-28 19:14 -0700

csiph-web