In Python, there is no way to automatically rewrite a name in a global or local area in response to bounces of other names. However, it should be possible to create a class that can track some values and have a member function that returns the value you called A. And, as @Alok noted, you can use property descriptors to create a member name that implicitly calls a function to return its value, so you can hide this function and treat the name as a plain old name.
class Trk(object):
"""Track some values and compute a function if any change"""
def __init__(self, name, fn, **objects_to_track):
def _trk_fn(self):
if any(self.__dict__[x] != self.original_objects[x] for x in self.original_objects):
self.value = self.saved_fn(self.__dict___)
for x in self.original_objects:
self.original_objects[x] = self.__dict__[x]
return self.value
self.original_objects = objects_to_track
self.__dict__.update(objects_to_track)
self.name = name
self.saved_fn = fn
self.fn = self._trk_fn()
self.value = self.fn()
Sorry, but I am very tired right now and I can not finish this example. I did not check either. But this shows one way to track values, and if they are different, do something else. You use it as follows:
trk = Trk(x, y, z)
trk.fn()
trk.x = new_value
trk.fn()
, , self.fn()
EDIT: , , self.value, self.original_objects . .
!