title: How can I add properties to a class using a decorator that takes a list of names as argument?
body: <p>I would like to add many dummy-properties to a class via a decorator, like this:</p>
  
  <pre><code>def addAttrs(attr_names):
    def deco(cls):
      for attr_name in attr_names:
        def getAttr(self):
          return getattr(self, "_" + attr_name)
        def setAttr(self, value):
          setattr(self, "_" + attr_name, value)
        prop = property(getAttr, setAttr)
        setattr(cls, attr_name, prop)
        setattr(cls, "_" + attr_name, None) # Default value for that attribute
      return cls
    return deco
  
  @addAttrs(['x', 'y'])
  class MyClass(object):
    pass
  </code></pre>
  
  <p>Unfortunately, the decoarator seems to keep the reference of <code>attr_name</code> instead of its content. Therefore, <code>MyClass.x</code> and <code>MyClass.y</code> access both <code>MyClass._y</code>:</p>
  
  <pre><code>a = MyClass()
  a.x = 5
  print a._x, a._y
  &gt;&gt;&gt; None, 5
  a.y = 8
  print a._x, a._y
  &gt;&gt;&gt; None, 8
  </code></pre>
  
  <p>What do I have to change to get the expected behavior?</p>