title: Global Object Definitions
body: <pre><code>class testClass(object):
    def __init__(self, val)
       self.val=val
  
  def function():
    variable = &quot;name&quot;
    x=&quot;value&quot;
    exec(str(variable) + &quot;=testClass('&quot; + str(x) + &quot;')&quot;)
  
  function()
  print(name.val)
  </code></pre>
  <p>This is test code for a different algorithm I'm using. It returns a name error for the var 'name'. Even when I put the print(name.wins) inside of test(), I still receive a name error. The class is definitely being defined as if I put print(&quot;test&quot;) within the constructor of testClass(), it prints just fine. Why does this not work?</p>
  <p>EDIT:
  I opted to use a dictionary rather than dynamic variable names.</p>