title: Python __setattr__ and __getattr__ for global scope?
body: <p>Suppose I need to create my own small DSL that would use Python to describe a certain data structure. E.g. I'd like to be able to write something like</p>
  
  <pre><code>f(x) = some_stuff(a,b,c)
  </code></pre>
  
  <p>and have Python, instead of complaining about undeclared identifiers or attempting to invoke the function some_stuff, convert it to a literal expression for my further convenience.</p>
  
  <p>It is possible to get a reasonable approximation to this by creating a class with properly redefined <code>__getattr__</code> and <code>__setattr__</code> methods and use it as follows:</p>
  
  <pre><code>e = Expression()
  e.f[e.x] = e.some_stuff(e.a, e.b, e.c)
  </code></pre>
  
  <p>It would be cool though, if it were possible to get rid of the annoying "e." prefixes and maybe even avoid the use of []. So I was wondering, is it possible to somehow temporarily "redefine" global name lookups and assignments? On a related note, maybe there are good packages for easily achieving such "quoting" functionality for Python expressions?</p>