title: Declare a static variable in an enum class
body: <p>I have an enum for colors. I wish to add a helper method "toRGB()" to the enum class that converts an instance of the enum to an RGB object. As an optimization, I wished to create the dictionary once as a static variable. However, the correct syntax seems to elude me.</p>
  
  <p>Can anyone suggest the right way to do this?</p>
  
  <pre><code>from enum import Enum
  
  class RGB:
      def __init__(self, r, g, b):
          pass
  
  class Color(Enum):
      RED = 0
      GREEN = 1
  
      __tbl = {
                RED:   RGB(1, 0, 0),
                GREEN: RGB(0, 1, 0)
              }
  
      def toRGB(self):
          return self.__class__.__tbl[self.value]
  
  c = Color.RED
  print(c.toRGB())
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:/Users/user/Desktop/test.py", line 20, in &lt;module&gt;
      print(c.toRGB())
    File "C:/Users/user/Desktop/test.py", line 17, in toRGB
      return self.__class__.__tbl[self.value]
  TypeError: 'Color' object does not support indexing
  </code></pre>