[Python-ideas] Positional only arguments
Jim Jewett
jimjjewett at gmail.com
Tue May 22 00:57:24 CEST 2007
> What I would like is for unpack to be '^' instead of '*', then you would
> have...
My first reaction was negative -- but then I remembered that I was
caught by this trap myself more than once, because of the asymmetry
between pack and unpack, with * magically doing the normally-right
thing.
So now I wonder if I wouldn't like if after all, and I'm instead
picking at the presentation, so you can make a stronger case.
On 5/21/07, Ron Adam <rrr at ronadam.com> wrote:
> Now if we use ^ for unpacking, and * for packing, it reduces the number of
> meanings for the '*' and fixes the context of positional and keyword only
> arguments.
> def f(a, ^(b=2, c=3), *rest): b and c are positional only here.
I don't think there should ever be positional-only arguments *after* a
keywordable argument. Perhaps
# a is a mandatory positional argument
# b is an optional positional argument
# c can be passed as a keyword, or as the third positional argument
def f(^a, ^b=2, c=3, *rest):
Or were you suggesting a tuple of the positional-only arguments, like
# a is a mandatory positional argument
# b is an optional positional argument
# c can be passed as a keyword, or as the third positional argument
def f(^(a, b=2), c=3, *rest):
> There is the possibility of extending this for use in other ways as well.
>
> xlist = [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
>
> alist = [^x for x in xlist]
>
> This would have list "extend" behavior instead of list "append" behavior.
So alist == [1, 2, 3, 4, 5, 6, 7, 8, 9]?
-jJ
More information about the Python-ideas
mailing list