[Python-ideas] Quick idea: defining variables from functions that take the variable name
Steven D'Aprano
steve at pearwood.info
Tue May 31 10:24:38 EDT 2016
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.
There are proven uses for passing a name to a function. Any time that an
object needs to know its own name, you have to pass it to the
constructor. But I can't think of any cases where you would want to do
something similar with item lookup.
> Or even attribute lookup with a trailing dot:
>
> attr -> my_object.
That fails the "grit on Uncle Timmy's monitor" test. The trailing dot is
easy to miss.
--
Steve
More information about the Python-ideas
mailing list