title: Is it possible to define a class constant inside an Enum?
body: <p>Python 3.4 introduces a new module <a href="http://docs.python.org/3.4/library/enum.html"><code>enum</code></a>, which adds an <a href="http://en.wikipedia.org/wiki/Enumerated_type">enumerated type</a> to the language. The documentation for <code>enum.Enum</code> provides <a href="http://docs.python.org/3.4/library/enum.html#planet">an example</a> to demonstrate how it can be extended:</p>
  
  <pre><code>&gt;&gt;&gt; class Planet(Enum):
  ...     MERCURY = (3.303e+23, 2.4397e6)
  ...     VENUS   = (4.869e+24, 6.0518e6)
  ...     EARTH   = (5.976e+24, 6.37814e6)
  ...     MARS    = (6.421e+23, 3.3972e6)
  ...     JUPITER = (1.9e+27,   7.1492e7)
  ...     SATURN  = (5.688e+26, 6.0268e7)
  ...     URANUS  = (8.686e+25, 2.5559e7)
  ...     NEPTUNE = (1.024e+26, 2.4746e7)
  ...     def __init__(self, mass, radius):
  ...         self.mass = mass       # in kilograms
  ...         self.radius = radius   # in meters
  ...     @property
  ...     def surface_gravity(self):
  ...         # universal gravitational constant  (m3 kg-1 s-2)
  ...         G = 6.67300E-11
  ...         return G * self.mass / (self.radius * self.radius)
  ...
  &gt;&gt;&gt; Planet.EARTH.value
  (5.976e+24, 6378140.0)
  &gt;&gt;&gt; Planet.EARTH.surface_gravity
  9.802652743337129
  </code></pre>
  
  <p>This example also demonstrates a problem with <code>Enum</code>: in the <code>surface_gravity()</code> property method, a constant <code>G</code> is defined which would normally be defined at class level - but attempting to do so inside an <code>Enum</code> would simply add it as one of the members of the enum, so instead it's been defined inside the method.</p>
  
  <p>If the class wanted to use this constant in other methods, it'd have to be defined there as well, which obviously isn't ideal.</p>
  
  <p>Is there any way to define a class constant inside an <code>Enum</code>, or some workaround to achieve the same effect?</p>