I am trying to simulate a pointer-like behavior for a python3 class attribute. In the following example I would like to have obj.b pointing to obj.a, such that if obj.a value changes at runtime obj.b value will change to.
# not working as expected
class A:
def __init__(self, value):
self.a = value
self.b = getattr(self, 'a')
obj = A('banana')
# now changing my mind
obj.a = 'apple'
# I would like to have obj.b == 'apple', not 'banana'
I imagine that I am trying to do a dirty trick that should be better avoided, but for my specific task it would be pretty helpful
bto be a property that returnsself.a. But I can't really understand what you are actually trying to do here.obj.aitself? what is the use-case?