title: Alias dictionary in python, Class vs dict
body: <p>I want to keep a set of field names as aliases (like <code>'fieldName' = 'f'</code>) in my python project. While I'm pretty sure the most straight forward way is to just keep a dict, like</p>
  
  <pre><code>F = {'_id'         :       '_id',
       'tower'       :       'T',
       'floor'       :       'F',
       'pos'         :       'P'
       }
  </code></pre>
  
  <p>I am thinking I can just write a class, like,</p>
  
  <pre><code>class F:
      def __init__():
          self._id         =       '_id',
          self.tower       =       'T',
          self.floor       =       'F',
          self.pos         =       'P'
  </code></pre>
  
  <p>The sole reason is then I can access the data using,</p>
  
  <p><code>get_var(f._id)</code> which is shorter and nicer looking compared to,</p>
  
  <p><code>get_var(F['_id'])</code></p>
  
  <p>Is it abusing python if I do it? and is there any advantages or disadvantages?</p>
  
  <p>These aliases will be read from a config file at startup and will not change through the running time.</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>From silas's answer, I cooked up this. Why would this be bad compared to your answer?</p>
  
  <pre><code>class Aliases:
      """ Class to handle aliases for Mongo fields. 
          TODO: Should these be read off from a config file?
      """
  
      def __init__(self):
          self._F = {
              '_id'         :       '_id',
              'tower'       :       'T',
              'floor'       :       'F',
              'pos'         :       'P',
              'stabAmplitude'   :   's',
              'totalEnergy' :       'z',
              ...
          }
  
      def __getattr__(self, name):
          """ Return the attributes from the alias dictionary instead of the 
              real attributes dictionary
          """
          try:
              return object.__getattribute__(self, '_F')[name]
          except KeyError:
              raise AttributeError('No attribute named %s.' % name)
  
      def __setattr__(self, name, value):
          """ No attributes should be changable """
          if name == '_F':
              return object.__setattr__(self, name, value)
          else:
              raise AttributeError('Attribute %s cannot be changed.', name)
  </code></pre>