Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'fashion.': 0.07; 'received:verizon.net': 0.07; 'terry': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'protocol': 0.15; 'arrays,': 0.16; 'does,': 0.16; 'extensible': 0.16; 'infinity': 0.16; 'iterator': 0.16; 'patch,': 0.16; 'reedy': 0.16; 'subject:arrays': 0.16; 'surprising': 0.16; 'temp': 0.16; 'translates': 0.16; 'wrote:': 0.16; 'issue.': 0.19; 'jan': 0.19; 'header:In-Reply-To:1': 0.22; 'pm,': 0.24; "python's": 0.24; "i'm": 0.27; 'lists': 0.28; 'temporary': 0.29; 'yield': 0.29; 'array': 0.30; 'ctypes': 0.30; 'over.': 0.30; "skip:' 10": 0.30; 'least': 0.31; 'patrick': 0.32; 'objects': 0.32; 'to:addr:python-list': 0.33; 'calling': 0.33; 'header:User-Agent:1': 0.34; 'right,': 0.34; 'header:X-Complaints- To:1': 0.35; 'response': 0.37; 'run': 0.37; 'but': 0.37; 'open': 0.37; 'think': 0.38; 'received:org': 0.38; 'everyone': 0.38; 'some': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'header:Mime- Version:1': 0.39; 'either': 0.39; 'else': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'you.': 0.62; 'increase': 0.63; 'due': 0.66; 'failure': 0.73; '99.9%': 0.84; 'efficiency,': 0.84; 'suffer': 0.84; 'maupin': 0.91; 'surprise': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Assigning generator expressions to ctype arrays Date: Thu, 27 Oct 2011 23:23:04 -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> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: <43aea5ad-bc9f-4e82-a9d5-74a06553a2ad@q16g2000yqn.googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1319772206 news.xs4all.nl 6952 [2001:888:2000:d::a6]:49176 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:15082 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