[Python-ideas] Quick idea: defining variables from functions that take the variable name

Paul Moore p.f.moore at gmail.com
Tue May 31 10:39:14 EDT 2016

On 31 May 2016 at 15:24, Steven D'Aprano <steve at pearwood.info> wrote:
> On Tue, May 31, 2016 at 02:12:05PM +0000, Joseph Martinot-Lagarde wrote:
>> It could work with indexing, like:
>>     key -> my_dict[]
>> instead of
>>     key = my_dict[key]
> That would have to be
>     key = my_dict['key']
> With the possible exception of the typing module, I don't see when that
> would be useful.

It's reminiscent of the recent "dictionary unpacking" discussion.

But it's doable without special-casing [] anyway:

key -> my_dict.get

[I still prefer "call the RHS with the name of the LHS as the
argument" over "inject the name of the LHS as the first argument of
the call present on the RHS", btw - mostly because it has fewer
restrictions and special cases to define]


More information about the Python-ideas mailing list