Python: callback when accessing the value of a variable?
<p>Suppose a function f() returns a value of arbitrary type, perhaps an object but possibly even a builtin type like <code>int</code> or <code>list</code>. Is there a way to assign a variable to that return value, and have a function of my choosing be called the first time the variable is used?</p>

<p>I suppose this is similar to lazy evaluation except that a reference to <code>x</code> exists and can be used by subsequent code.</p>

<p>It might look like this:</p>

<pre><code>x = f() # f is a function, assign variable to return value, but return value is unknown

# do something arbitrary with x
return str(x) # this calls a callback attached to x, which returns the value of x to be used
</code></pre>

<p>Again, I want to do this on any type, not just an object instance.</p>
