[Python-ideas] Quick idea: defining variables from functions that take the variable name
Steven D'Aprano
steve at pearwood.info
Thu Jun 2 08:45:21 EDT 2016
On Wed, Jun 01, 2016 at 09:04:29PM +0200, Sven R. Kunze wrote:
> I consider a special syntax for this narrow kind of usecase way too much
> as it doesn't seem very flexible and extensible in the future.
>
> Dunder methods/attributes/variables allow far more.
There's nothing to extend. It's a simple problem: how to give the right
hand side of an assignment access to the name of the assignment target
without having to type the name again as a string.
If you think that problem is too trivial to bother solving, that's a
reasonable opinion to hold.
But if you want to extend it to solve "far more" (whatever you mean by
that), please don't hijack this thread. If you think of some other
problems you would like to solve (whatever they might be), please feel
free to propose a solution to them in another thread. But *this*
discussion is about solving *this problem*:
Some (but not all) functions need to know the name of their
assignment target, so that the object they return can give
itself a name that matches that target. Or to put it another
way, some objects need to know their own name. The existing
solution to that is simple, but inelegant and annoying: you
have to manually type the name as a string and pass it as an
argument to the function.
If you want to solve some other problem, please do! But that's not part
of this thread, and if the proposed solution to *this* problem doesn't
solve *your* problem, that's irrelevant.
--
Steve
More information about the Python-ideas
mailing list