title: Python: Using a YAML to auto create class methods
body: <p>I have been trying to create a bunch of similar methods using a <code>YAML</code> configuration file. However, I have been unable to find something online or figure it out.</p>
  
  <p><code>example.yml</code></p>
  
  <pre><code>attributes:
    - a
    - b
    - c
  </code></pre>
  
  <p>example class</p>
  
  <pre><code>import yaml
  
  class Test:
      def __init__(self):
          with open('example.yml', 'rb') as f:
              attrib_list = yaml.load(f)
  
          _list = []
          for name in attrib_list:
              _list.append(self.__setattr__('_' + name, None))
  
  # create similar methods in a loop
           for name, _ in zip(attrib_list, _list):
               @property
               def name(self):  # I know name is a string so cannot be this way but how if this can be done?
                   return _
  
               @name.setter
               def __set + _(self, v):  # __set + '_' + name as method name
                   pass
  
               @name.getter
               def __get + _(self):  # __get + '_' + name as method name
                   pass
  </code></pre>
  
  <p>Is there efficient way to create many similar methods this way by looping through a configuration file?</p>
  
  <p>Or is there a better way to handle something of this nature?</p>
  
  <p>Thanks.</p>