title: Dynamically Create Static Variables (Enum hack)
body: <p>I'm trying to create a set of states for a <code>Node</code> class. Normally, I would do this by setting each <code>Node</code> instance's <code>state</code> variable to an <code>int</code>, and document which int corresponds to which state (since I don't have <code>enum</code>s).<br>
  This time, I'd like to try something different, so I decided to go with this:</p>
  
  <pre><code>class Node:
    state1 = 1
    state2 = 2
  
    def __init__(self):
      ...
  </code></pre>
  
  <p>This works well. However, I run into a problem where I have a LOT of states - too many to manually type out. Further, with that many states, I might make an error and assign the same <code>int</code> to two states. This would be a source of bugs when testing for states (e.g.: <code>if self.state==Node.state1</code> might fail if <code>Node.state1</code> and <code>Node.state2</code> were both <code>3</code>).</p>
  
  <p>For this reason, I would like to do something like this:</p>
  
  <pre><code>class Node:
    def __init__(self):
      ...
  ...
  
  for i,state in enumerate("state1 state2".split()):
    setattr(Node, state, i)
  </code></pre>
  
  <p>While this would fix human errors in assigning values to states, it's quite ugly, as class variables are being set outside the class definition.</p>
  
  <p>Is there a way I could set class variables within the class definition in this manner? I would ideally like to do this:</p>
  
  <pre><code>class Node:
    for i,state in enumerate("state1 state2".split()):
      setattr(Node, state, i)
  </code></pre>
  
  <p>... but that won't work as <code>Node</code> hasn't been defined yet, and will result in a <code>NameError</code></p>
  
  <p>Alternatively, do <code>enum</code>s exist in python3.3?</p>
  
  <p>I'm on Python3.3.2, if it matters</p>