*expression and iterables

Discussion in 'Python' started by Steven Bethard, Aug 20, 2004.

  1. 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.:

    >>> def rangegen(n):

    .... for i in range(n):
    .... yield i
    .... print "exhausted"
    ....
    >>> def f(*args):

    .... print "f"
    .... for arg in args:
    .... print arg
    ....
    >>> f(*rangegen(3))

    exhausted
    f
    0
    1
    2

    It would be nice if the iterable was only consumed as necessary, e.g.:

    >>> f(*rangegen(3))

    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.
    Steven Bethard, Aug 20, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    278
  2. John Reese
    Replies:
    10
    Views:
    571
    Carl Banks
    Nov 14, 2006
  3. VTay1410

    Expression 3 and Expression 4

    VTay1410, Jun 26, 2010, in forum: ASP General
    Replies:
    1
    Views:
    704
    Evertjan.
    Jun 26, 2010
  4. Thomas Bach
    Replies:
    19
    Views:
    275
    Ramchandra Apte
    Oct 3, 2012
  5. Ian Kelly
    Replies:
    0
    Views:
    190
    Ian Kelly
    Sep 29, 2012
Loading...

Share This Page