Suppose I have in python this object
class Foo:
def __init__(self, val):
self.val = val
and these two variables
a=Foo(5)
b=a
both b
and a
refer to the same instance of Foo()
, so any modification to the attribute .val
will be seen equally and synchronized as a.val
and b.val
.
>>> b.val
5
>>> b.val=3
>>> a.val
3
Now suppose I want to say a=Foo(7)
. This will create another instance of Foo, so now a
and b
are independent.
My question is: is there a way to have b
readdressed automatically to the new Foo() instance, without using an intermediate proxy object? It's clearly not possible with the method I presented, but maybe there's some magic I am not aware of.