title: Can Python instance methods be automatically defined at __init__ time?
body: <p>I'm wondering if instance methods can be created automatically in Python when <code>__init__</code> is executed. Consider this code example where a class is defined to handle some audio file format metadata (exceptions handling and not relevant stuff omitted):</p>
  <pre><code>__tags__ = ['album', 'artist', 'date', 'genre', 'title', 'tracknumber']
  
  class Tags():
      def __init__(self):
          for tag in __tags__:
              setattr(self, tag, None)
  
      def print(self):
          for k, v in self.__dict__.items():
              if v:
                  print('{}: {}'.format(k, str(v)))
  
      def get(self, *pa):
          ret = [getattr(k) for k in pa if k in __tags__]
          return ret if len(pa)&gt;1 else ret[0]
  
      def set(self, **ka):
          for k, v in ka.items():
              if k in __tags__:
                  setattr(self, k, str(v))
  </code></pre>
  <p>Now:</p>
  <pre><code>    mytags = Tags()
      mytags.set(album='The best of Ennio Morricone', artist='Various Artists')
      mytags.print()
      print()
      mytags.set(genre='Soundtrack', tracknumber=3)
      mytags.set(title='Secret Of The Sahara')
      mytags.print()
      print(mytags.album is mytags.get('album'))
  </code></pre>
  <p>prints:</p>
  <pre><code>album: The best of Ennio Morricone
  artist: Various Artists
  
  album: The best of Ennio Morricone
  artist: Various Artists
  genre: Soundtrack
  title: Secret Of The Sahara
  tracknumber: 3
  True
  </code></pre>
  <p>Suppose now I want to add <code>get_&lt;tag&gt;/set_&lt;tag&gt;</code> methods for every single tag, i.e. <code>mytags.set_album(album)</code> or <code>title=mytags.get_title()</code>. Given that <code>mytags.set_album(album)</code> translates to <code>mytags.set({'album':album,})</code>, is there a pythonic way to automatically create these methods when the instance is created?
  Stupid non-working example just to try to explain what I mean:</p>
  <pre><code>    class Tags():
          def __init__(self):
              for tag in __tags__:
                  setattr(self, tag, None)
                  setattr(self, 'set_'+tag&lt;reference to passed in argument&gt;,
                          &lt;reference to the respective self.set() method&gt;)
  </code></pre>
  <p>This would save a lot of typing and, above all, it wouldn't require any change should <code>__tags__</code> be updated.</p>