Re: proposal: Ellipsis in argument list

Discussion in 'Python' started by Stefan Behnel, Jan 12, 2013.

  1. Szabolcs Blága, 12.01.2013 14:30:
    > I have an idea that the Ellipsis object could be used in function calls.
    > The "..." syntax should automagically turn into an Ellipsis positional
    > argument.
    >
    > def f(*args):
    > ext_args = []
    > for i, a in enumerate(args):
    > if a is Ellipsis:
    > ext_args.extend([x for x in range(args[i-1]-1, args[i+1])])
    > else:
    > ext_args.append(a)
    > return ext_args
    >
    > Calling it for the above example specifically:
    >
    > >>> f(34, ..., 43)

    > [34, 35, 36, 37, 38, 39, 40, 41, 42, 43]
    >
    > That might be useless or someone might say it is confusing, but I think it
    > would be relatively easy to implement and a nice little syntactic "sugar".


    Not sure what exactly you are proposing here, this works for me:

    Python 3.2.3 (default, Oct 19 2012, 19:53:16)
    [GCC 4.7.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> def f(*args): print(args)
    >>> f(34, ..., 43)

    (34, Ellipsis, 43)

    Stefan
    Stefan Behnel, Jan 12, 2013
    #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. Nathan Sokalski
    Replies:
    2
    Views:
    510
    Hans Kesting
    Feb 14, 2006
  2. Chris Perkins

    Ellipsis outside a slice

    Chris Perkins, Oct 8, 2003, in forum: Python
    Replies:
    1
    Views:
    920
    Terry Reedy
    Oct 9, 2003
  3. Wayne Folta

    Ellipsis usage?

    Wayne Folta, Feb 18, 2004, in forum: Python
    Replies:
    2
    Views:
    4,896
    Peter Otten
    Feb 18, 2004
  4. Ben Kial
    Replies:
    1
    Views:
    642
    Eric Enright
    Nov 15, 2004
  5. Chris Kaynor

    Re: proposal: Ellipsis in argument list

    Chris Kaynor, Jan 14, 2013, in forum: Python
    Replies:
    0
    Views:
    126
    Chris Kaynor
    Jan 14, 2013
Loading...

Share This Page