[Python-Dev] iter alternate form and *args and **kwargs

Michael Hudson mwh at python.net
Thu Jun 16 17:04:53 CEST 2005


Steven Bethard <steven.bethard at gmail.com> writes:

> On 6/15/05, Benji York <benji at benjiyork.com> wrote:
>> Steven Bethard wrote:
>> > I would prefer that the alternate iter() form was broken off into
>> > another separate function, say, iterfunc(), that would let me write
>> > Jp's solution something like:
>> >
>> > for chunk in iterfunc('', f1.read, CHUNK_SIZE):
>> >     f2.write(chunk)
>> 
>> How about 2.5's "partial":
>> 
>> for chunk in iter(partial(f1.read, CHUNK_SIZE), ''):
>>     f2.write(chunk)
>
> Yeah, there are a number of workarounds.  Using partial, def-ing a
> function, or using a lambda will all work.  My point was that, with
> the right API, these workarounds wouldn't be necessary. 

Well, I dunno.  I can see where you're coming from, but I think you
could make the argument that the form using partial is clearer to read
-- it's not absolutely clear that the CHUNK_SIZE argument is intended
to be passed to f1.read.  Also, the partial approach works better when
there is more than one callable.

Cheers,
mwh

-- 
  Like most people, I don't always agree with the BDFL (especially
  when he wants to change things I've just written about in very 
  large books), ... 
         -- Mark Lutz, http://python.oreilly.com/news/python_0501.html


More information about the Python-Dev mailing list