title: Programmatically creating variables in Python
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1429814/how-to-programmatically-set-a-global-module-variable">How to programmatically set a global (module) variable?</a>  </p>
  </blockquote>
  
  
  
  <p>I have a class called Variable defined as so:</p>
  
  <pre><code>class Variable():
      def __init__(self, name):
          self.name = name
          self._value = None
      def value(self):
          return self._value
      def __repr__(self):
          return self.name
  </code></pre>
  
  <p>I want to create 26 capital single letter instances of Variable like this:</p>
  
  <pre><code>A = Variable('A')
  B = Variable('B')
  ...
  Z = Variable('Z')
  </code></pre>
  
  <p>So far I've tried various solutions, and the best I've come up with is:</p>
  
  <pre><code>from string import uppercase
  for char in uppercase:
      exec "%s = %s" % (char, Variable(str(char))) in None
  </code></pre>
  
  <p>However, this doesn't run and gives me this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\Administrator\Dev\python\truthtable\truthtable.py", line 7, in &lt;module&gt;
      exec "%s = %s" % (char, Variable(str(char))) in None
    File "&lt;string&gt;", line 1, in &lt;module&gt;
  NameError: name 'A' is not defined
  </code></pre>
  
  <p>What am I doing wrong?</p>