How do I put off attribute access in Python?
Let's assume we have:
def foo():
...
class Bar:
...
bar = Bar()
Is it possible to implement Bar so that any time bar is accessed, a value returned by the callback foo() would be provided?
bar name already exists in the context. That's why it's access semantics should be preserved (it cannot be a callable, turning bar into a property of a class, using SomeClass.bar instead of bar also won't work). I need to keep everything as-is, but change the program so that bar would refer to on-the-fly generated data by foo().
UPD: Thanks all for your answers, from which it seems impossible to do this type of thing in Python. I'm gonna find a workaround.