[Python-ideas] Quick idea: defining variables from functions that take the variable name
Paul Moore
p.f.moore at gmail.com
Wed Jun 1 11:42:39 EDT 2016
On 1 June 2016 at 16:10, Sven R. Kunze <srkunze at mail.de> wrote:
> That's the current way. If now, the compiler would assign "x" to a special
> dunder attribute/variable, that would allow __init__ to extract that name
> and use it as if it were a parameter:
>
> class AutoSymbol:
> def __init__(self):
> self.name = __assigned_name__ # that's me :)
>
Why doesn't the assignment here set __assigned_name__ too, and
override the value assigned by the "outer" assignment?
Also, as someone else pointed out, in
a = b = c = AutoSymbol()
what would __assigned_name__ be? The advantage of a special operation
is that it gives you a way of pointing out precisely *which* name
assignment we want to remember...
Paul
More information about the Python-ideas
mailing list