[Python-ideas] Short form for keyword arguments and dicts

Joshua Landau joshua.landau.ws at gmail.com
Sat Jun 29 18:20:30 CEST 2013


On 27 June 2013 13:55, Nick Coghlan <ncoghlan at gmail.com> wrote:
> As far as this whole thread goes, though, we're still in the situation
> where the simplest mechanisms Python currently has to extract a submap
> from a mapping are a dict comprehension and operator.itemgetter. These
> proposed changes to function calling syntax then target a very niche
> case of that broader problem, where the mapping is specifically the
> current local variables and the destination for the submap is a
> function call with like named parameters. This is *not* the calibre of
> problem that prompts us to make Python harder to learn by adding new
> syntax.

Sorry for the necromancy; but I just want to shine some inspiration I
had recently on this:

We *do* have a way of extracting a submap from a dict.

We *already* have a way of writing

    foo = foo

across scopes, as we want to do here.

This problem *has* been solved before, and it looks like:

    from module import these, are, in, the, submap


I haven't been able to find a really good syntax from this, but something like:

1) foo(a, b, **(key1, key2 from locals()))

2) {**(key1, key2 from locals())}

3) import key1, key2 from {"key1": 123, "key2": 345}

etc.

And, á mon avis, it's a hell of a lot better than previous proposals
for (1) and (2) from this thread, and (3) from other threads.

Again, not a proposal per se but a revelation.


More information about the Python-ideas mailing list