title: How to switch between two sets of attribute values, depending on an internal state?
body: <p>I have a class holding some scientific data. Depending on an internal state, the values of this class can appear as normalized (i.e. unitless), or non-normalized. The values are always stored as normalized, but if the object is set in non-normalized status, the user-accessible properties (and methods) will give the non-normalized values. This way the class appears as non-normalized, while there's no need to duplicate the stored values.</p>
  <p>Right now I implemented this using getters. While it works, it gives a lot of repeating structure, and I wonder if there's a more Pythonic way of managing this without overcomplicating things.</p>
  <p><strong>Am I doing this right? Is there a more elegant way to switch between two sets of data in a similar fashion?</strong></p>
  <pre><code>class CoolPhysicsData(object):
      def __init__(self, lambda0, *args, normed=False):
          self.lambda0 = lambda0     # some normalization factor (wavelength of some wave)
          self.normalized = normed      # user can change this state as he pleases
          self._normed_tmin, self._normed_tmax, self._normed_r = self.calculate_stuffs(*args)
          ...
  
      @property
      def tmin(self):
          if self.normalized:
              return self._normed_tmin
          else:
              return denormalize(self.lambda0, self._normed_tmin, unit_type=&quot;time&quot;)
  
      @property
      def tmax(self):
          if self.normalized:
              return self._normed_tmax
          else:
              return denormalize(self.lambda0, self._normed_tmax, unit_type=&quot;time&quot;)
  
      @property
      def r(self):
          if self.normalized:
              return self._normed_r
          else:
              return denormalize(self.lambda0, self._normed_r, unit_type=&quot;len&quot;)
  
      ...  # about 15 getters alike these
  </code></pre>