title: creating a class that behaves like any variable but has callback on change/read
body: <p>I would like to create a class that behaves as a python variable but calls some callback function when the "variable" is changed/read.</p>
  
  <p>In other words, I'd like to be able to use the class as follows:</p>
  
  <pre><code>x=myClass(change_callback, read_callback)
  </code></pre>
  
  <p>defines x as an instance of myclass. The constructor (<strong>INIT</strong>) takes 2 functions as paramater: a function to be called each time  x is changed, and a function to be called each time x is "read"</p>
  
  <p>The following statement:</p>
  
  <pre><code>x=1
  </code></pre>
  
  <p>would "save" 1 and trigger a call to <code>change_callback(1)</code> which could do anything.</p>
  
  <p>The following statement:</p>
  
  <pre><code>a=x
  </code></pre>
  
  <p>would retrieve the stored value and call <code>read_callback()</code> which would possibly change  the stored value and do other things.</p>
  
  <p>I would like this to work with any type, e.g. to be able to write things like:</p>
  
  <p><code>x=[1 2 3]</code> which would trigger <code>change_callback([1 2 3])</code></p>
  
  <p><code>x.append(4)</code> would trigger <code>change_callback([1 2 3 4])</code> (and possibly a call to <code>read_callback()</code> before)</p>
  
  <p><code>x={'a':1}</code> would trigger <code>change_callback({'a':1})</code></p>
  
  <p><code>print(x)</code> would trigger a call to read_callback()...and return the last stored value for printing, of course.</p>
  
  <p>The idea is that any access to the variable could be logged, or generate other calculation... seemlessly.</p>
  
  <p>I get the feeling this should be possible, but I don't really see what my object should inherit from...
  If I have to restrict me to one type,e.g. a list, is there any way to redefine all assignment operators (including methods like append()...) in "one go", keeping the original behaviour (the base class method) and adding the callback...</p>
  
  <p>Or are there more appropriate ways (modules...) to achieve the same goals...?</p>
  
  <p>Thanks in advance,</p>