* operator--as in *args?

Alex Martelli aleax at mac.com
Mon Mar 19 03:05:33 CET 2007


Gabriel Genellina <gagsl-py2 at yahoo.com.ar> wrote:
   ...
> > As far as it goes, yes.  More generally, with any iterable x, the *x
> > construct in function call will pass as positional arguments exactly
> > those items which (e.g.) would be printed by the loop:
> >     for item in x: print x
> >
> > [[this applies to iterators, generators, genexps, and any other iterable
> > you may care to name -- not just lists, tuples, dicts, but also sets,
> > files open for reading [the items are the lines], etc, etc]].
> 
> But the language reference says "sequence", not "iterable"  

Yes, Python's docs often say "sequence" where they in fact mean
"iterable".  I count (on all the .tex files under Doc/ in a current SVN
tree) 854 occurrences of "sequence" versus 251 occurrences of
"iterable", and I suspect the correct ratio would be rather close to the
reverse:-).

> If allowing f(*d) is actually the intended behavior, maybe the wording in
> the reference should be updated. If not, f(*d) should still raise an error.

Patches to the docs will doubtlessly be welcome (though fixing 1 out of
a suspected 600 or so misuses won't make a huge difference, it's still
definitely better than nothing:-).


Alex



More information about the Python-list mailing list