*expression and iterables

S

Steven Bethard

So I was looking at the Python 3.0 wiki
(http://www.python.org/moin/Python3_2e0) and noticed that one of the
major changes would be that builtin classes and functions would take
and return iterators instead of lists. Along these same lines, I'm
wondering if we could also add the feature that a *expression
parameter produces an iterable instead of a tuple.

Right now, using the *expression syntax with an iterable causes that
iterable to be consumed at the time of the function call, e.g.:
.... for i in range(n):
.... yield i
.... print "exhausted"
........ print "f"
.... for arg in args:
.... print arg
....exhausted
f
0
1
2

It would be nice if the iterable was only consumed as necessary, e.g.:
f
0
1
2
exhausted

This would mean that izip(*izip(x)) would work without reading all the
elements of izip(x) into memory.

If I understand (http://docs.python.org/ref/calls.html) correctly,
parameter values are filled with the following sequence:
* use values from positional arguments
* use values from *expression argument
* use values from keyword arguments
* use values from **expression argument
So either the *expression iterable gets run to completion, fills some
parameter values, and the sequence proceeds as normal, or it runs
until all parameter values are filled, and then it's passed in as the
*args parameter. Doesn't seem too unreasonable...

Is this implementable? If so, it seems desirable -- is it something
that could be added to the Python 3.0 wiki? (I'd love it now, of
course, but it's backwards incompatible =)

Steve

P.S. I didn't add it to the wiki myself because it sorta seemed like
that wiki was intended only for the goals GvR had already suggested.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top