[Python-Dev] iter alternate form and *args and **kwargs (Was: Wishlist: dowhile)

Steven Bethard steven.bethard at gmail.com
Thu Jun 16 03:17:53 CEST 2005


Jp Calderone:
>  for chunk in iter(lambda: f1.read(CHUNK_SIZE), ''):
>      f2.write(chunk)

Phillip J. Eby:
> More seriously, I think your translation makes an excellent argument in
> *favor* of having a do/while statement for greater clarity.  :)

Michael Chermside
> Interesting... I had the opposite reaction.

I, too, thought that Jp's solution was quite easy to read, though
every few months I forget about iter()'s alternate form again. ;-)

Perhaps one of the things that makes Jp's solution slightly hard to
read is the fact that f1.read must be wrapped in a function (in Jp's
example, a lambda).  It reminds me of one of my minor gripes about the
standard lib -- a number of functions that take another function as an
argument don't take *args and **kwargs to be passed to that function
when it's called.  The iter() alternate form is a common example of
this.  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)

Even better would be to add the *args and **kwargs to iter() directly,
but of course, that would be backwards incompatible.

Anyway, in general, I'd like to see the standard lib in Python 3K
convert functions like iter()'s alternate form to functions like
iterfunc(), i.e. provide *args and **kwargs whenever possible.

Steve
-- 
You can wordify anything if you just verb it.
        --- Bucky Katt, Get Fuzzy


More information about the Python-Dev mailing list