title: Pythonic way to dynamically add properties and setters
body: <p>I'm working on a library for a 3D application that wraps the application's functionality into a set of Python classes, as well as adding additional functionality that the application doesn't have.</p>
  
  <p>I have a set of properties in my base class to add attributes to a node using the existing API, but I'd like a more elegant way of adding attributes dynamically. I currently have this code (which probably won't make much sense without familiarity with the 3D application) but the important bit is the </p>
  
  <pre><code># Add block properties
  </code></pre>
  
  <p>and</p>
  
  <pre><code># PROPERTIES
  </code></pre>
  
  <p>code.</p>
  
  <pre><code>class Block(pyunify.Transform):
      def __init__(self, name = "Character"):
          pyunify.Transform.__init__(self, name)
          self.LockTransform()
  
  
  class Spine(Block):
      def __init__(self, name = "Character", numberOfJoints=6):
          Block.__init__(self, name+"_spine")
  
          # Add block properties
          self.AddAttr("numberOfJoints", "long")
          self.SetAttr("numberOfJoints", numberOfJoints)
  
          # Create block template
          self.Template()
  
      # PROPERTIES
      @property
      def numberOfJoints(self):
          return self.GetAttr("numberOfJoints")
  
      @numberOfJoints.setter
      def numberOfJoints(self, num):
          self.SetAttr("numberOfJoints", num)
  </code></pre>
  
  <p>So I could foresee additional classes having a lot more properties, and the way I have it now, for every property I have to add it in _init__</p>
  
  <pre><code>self.AddAttr("numberOfJoints", "long")
  self.SetAttr("numberOfJoints", numberOfJoints)
  </code></pre>
  
  <p>and then I have to add 2 additional functions in my class, a getter and setter, for that property so that I can call it within my class as self.numberOfJoints and it will interact with the class itself as well as setting the correct attributes on the accompanying node in the 3D application.</p>
  
  <pre><code>    @property
      def numberOfJoints(self):
          return self.GetAttr("numberOfJoints")
  
      @numberOfJoints.setter
      def numberOfJoints(self, num):
          self.SetAttr("numberOfJoints", num)
  </code></pre>
  
  <p>The only difference with the additional property functions will be the name, so I was wondering if there was a way I could create an AddProperty function in my base Block class so that I could just do this in my _init__ function:</p>
  
  <pre><code>self.AddProperty("numberOfJoints", "long")
  self.numberOfJoints = 5
  </code></pre>
  
  <p>and it will dynamically create the getter and setter functions in addition to running the current _init__ line of</p>
  
  <pre><code>self.AddAttr("numberOfJoints", "long")
  </code></pre>
  
  <p>Any help would be appreciated!</p>
  
  <p>Thanks!</p>