[Python-ideas] aliasing
Steven D'Aprano
steve at pearwood.info
Wed Aug 31 14:41:51 CEST 2011
Peio Borthelle wrote:
>>>> a = 2
>>>> b = alias("a")
>>>> a = 'foo'
>>>> b
> 'foo'
I have often thought that would be a nice to have feature, but to be
honest, I have never found a use for it that was absolutely necessary. I
have always found another way to solve the problem.
You can always use one level of indirection:
a = [2]
b = a
a[0] = 'foo' # Not a='foo'
b[0]
=> print 'foo'
To make it work using just ordinary assignment syntax, as you suggest,
requires more than just an "alias" function. It would need changes to
the Python internals. Possibly very large changes. Without a convincing
use-case, I don't think that will happen.
So even though I think this would be a neat feature to have, and
possibly even useful, I don't think it is useful enough to justify the
work needed to make it happen.
--
Steven
More information about the Python-ideas
mailing list