title: How do you programmatically set an attribute?
body: <p>Suppose I have a python object <code>x</code> and a string <code>s</code>, how do I set the attribute <code>s</code> on <code>x</code>? So:</p>
  
  <pre><code>&gt;&gt;&gt; x = SomeObject()
  &gt;&gt;&gt; attr = 'myAttr'
  &gt;&gt;&gt; # magic goes here
  &gt;&gt;&gt; x.myAttr
  'magic'
  </code></pre>
  
  <p>What's the magic? The goal of this, incidentally, is to cache calls to <code>x.__getattr__()</code>. </p>