Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: proposal: Ellipsis in argument list

Reply
Thread Tools

Re: proposal: Ellipsis in argument list

 
 
Chris Kaynor
Guest
Posts: n/a
 
      01-14-2013
On Sat, Jan 12, 2013 at 5:30 AM, Szabolcs Blága <>wrote:

> Dear All,
>
> 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"..
>
>

The basis for adding syntactic sugar is closer to: Is this something that
cannot be done clearly without the change, and is commonly useful?
Also, as Stefan showed, this is already valid syntax with differing
meaning, and thus could break existing code, making the threshold for
adding it even harder.

This change doesn't seem to useful, and can be easily done already:
f(range(34, 43))

Additionally, a decorator could easily be written to do this if you find
this is a pattern you commonly use for specific functions (untested), or
you can use your expansion function for other cases:

def ellipsisExpand(func):
def newFunc(*args, **kwargs):
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 func(*ext_args, **kwargs)

Then, you use this like:
@ellipsisExpand
def f(arg):
print arg



> Best regards,
>
> Szabolcs Blaga
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: proposal: Ellipsis in argument list Stefan Behnel Python 0 01-12-2013 02:08 PM
The Ellipsis (.) Character Is Not Showing Up When Read From A Text File Nathan Sokalski ASP .Net 2 02-14-2006 08:49 AM
How to pass variable argument list to another function w/ variable argument list? Ben Kial C Programming 1 11-15-2004 01:51 AM
Ellipsis usage? Wayne Folta Python 2 02-18-2004 09:54 PM
Ellipsis outside a slice Chris Perkins Python 1 10-09-2003 02:10 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57