title: python decorator adds function to list on object
body: <p>In python I need to make a list of properties on my class which I may serialise, it is cumbersome to list these at the top of the class. Instead I would like to use a decorator in the same way @property is used, ie something like this:</p>
  
  <pre><code>class MyClass(object):
  
      # I dont like having to do this for example
      #__list_of_props_to_serialise__ = ['my_prop',]
  
      @property
      @serialise
      def my_prop(self):
          return "this is my property"
  
      def serialise(self):
          return {f: self.getattr(f) for f in self.__list_of_props_to_serialise__}
  </code></pre>
  
  <p>where <code>__list_of_props_to_serialise__</code> is updated on the object by the decorator when the class is built so I dont need the commented out lines at the start.</p>
  
  <p>The problem is when I come to write the decorator I don't have access to the class or object until I actually call the <code>my_prop</code> function so I cannot add it. Am I 'doing it wrong', Is there a better way to do this, or can this be done somehow?</p>
  
  <p>If this can be done can some please show a decorator function I can use, else if there is a better way please give an example.</p>
  
  <p>Thanks.</p>