title: Add attribute to python class
body: <p>Consider the following code:</p>
  
  <pre><code>class Foo():
  
      pass
  
  
  Foo.entries = dict()
  
  
  a = Foo()
  a.entries['1'] = 1
  
  b = Foo()
  b.entries['3'] = 3
  
  print(a.entries)
  </code></pre>
  
  <p>This will print:</p>
  
  <pre><code>{'1': 1, '3': 3}
  </code></pre>
  
  <p>because the entries is added as static attribute. Is there a way monkey patch the class definition in order to add new attributes (without using inheritance).</p>
  
  <p>I managed to find the following way but it looks convoluted to me:</p>
  
  <pre><code>def patch_me(target, field, value):
      def func(self):
          if not hasattr(self, '__' + field):
              setattr(self, '__' + field, value())
          return getattr(self, '__' + field)
      setattr(target, field, property(func))
  
  patch_me(Foo, 'entries', dict)
  </code></pre>