greg.ewing at canterbury.ac.nz
Thu Sep 1 00:52:11 CEST 2011
Steven D'Aprano wrote:
> Peio Borthelle wrote:
>>>>> a = 2
>>>>> b = alias("a")
>>>>> a = 'foo'
> I have often thought that would be a nice to have feature,
Seems to me it would be a confusing-to-have feature. By now
it's deeply embedded in Python programmers' brains that
assignment to a bare name can only change which object that
name refers to, and can't have any other side effects.
> You can always use one level of indirection:
> a = 
> b = a
> a = 'foo' # Not a='foo'
> => print 'foo'
Also, if you're willing to use an object attribute rather
than a bare name, you can get the same effect using a
def set_b(self, value):
self.a = value
b = property(get_b, set_b)
s = Switcheroo()
s.a = 17
s.b = 42
More information about the Python-ideas