title: Namespace for class declaration in file executed at runtime
body: <p>I wrote a program to allow users to give me a class name and the file that defines that class like so:</p>
  
  <pre><code>    input = raw_input("Input the new classname with a space and then the file name defining the class")
      class_name, file_name = input.split(" ")
  </code></pre>
  
  <p>I then execute the file defining the class:</p>
  
  <pre><code>  execfile(file_name)
  </code></pre>
  
  <p>and try to create an instance of the newly defined class:</p>
  
  <pre><code>    d[k] = eval(new_class)(**d[k])
  </code></pre>
  
  <p>However this creates the following error:</p>
  
  <pre><code>    d[i] = eval(new_class)(**d[i])
    File "&lt;string&gt;", line 1, in &lt;module&gt;
  NameError: name 'MeasureDay' is not defined
  </code></pre>
  
  <p>This is after I fed in the following class definition that was executed:</p>
  
  <pre><code>class MeasureDay:
      print("defining measureday")
      def __init__(self, **kargs):
          self.day = kwargs.get('day', -1)
          self.measurement_value = kwargs('measurement_value', -1)
  
      def __str__(self):
          return "here is a custom defined string for MeasureDay"
  </code></pre>
  
  <p>I know the class definition was executed because I see the logged statement "defining measureday" as desired. </p>
  
  <p><strong>What am I doing wrong? I am guessing this has to do with some namespace convention. Do I need to define a namespace when I define classes like so, and if so how would I do it. Otherwise, what is the problem?</strong></p>
  
  <p>Thanks for any suggestions.</p>