[Python-ideas] Keyword only argument on function call

Anders Hovmöller boxed at killingar.net
Thu Sep 6 22:44:51 EDT 2018



> For calling, we can use 
> https://docs.python.org/3/library/functions.html#locals 
>
>       >>> lcls = locals() 
>
>       >>> a = 'apple' 
>       >>> b = 'banana' 
>       >>> c = 'cherry' 
>
>       >>> dict((k, lcls[k]) for k in ('a', 'b', 'c')) 
>       {'b': 'banana', 'c': 'cherry', 'a': 'apple'} 
>
> So in his example 
>
>        foo(a=a, b=b, c=c, d=3, e=e) 
>
> one could instead write 
>
>       foo(d=3, **helper(locals(), ('a', 'b', 'c', 'e'))) 
>
> or perhaps better 
>
>     helper(locals(), 'a', 'b', 'c', 'e')(foo, d=3) 
>
> where the helper() picks out items from the locals(). And in the 
> second form, does the right thing with them. 
>

Sure. This was the argument against f-strings too. 

In any case I'm not trying to solve a problem of how to extract things from 
the local namespace anymore than "foo(a, b)" is. I'm trying to minimize the 
advantage positional arguments have over keyword arguments in brevity. If 
that makes sense?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180906/2ef85272/attachment.html>


More information about the Python-ideas mailing list