title: Passing arguments to python eval()
body: <p>I'm doing genetic programming framework and I need to be able to execute some string representing complete python programs. I'm using Python 2.7. I have a config class in which the primitive sets are defined. Lets say</p>
  
  <pre><code>class Foo():
      def a(self,x):
          return x
  
      def b(self,y):
          return y
  </code></pre>
  
  <p>I'm extracting the functions with the python inspect module and I want to create some executable source code with imports and everything. I end up with a string that looks like this</p>
  
  <pre><code>import sys
  
  def a(x,y):
      return x
  
  def b(y):
      return y
  
  def main(x,y)
      lambda x,y: a(b(y),a(x,y))
  
  main(*sys.argv)
  </code></pre>
  
  <p>My problem is that I don't know how to pass command line arguments to the string I'm running with <code>eval()</code>. <strong>How can I pass command line arguments to a source file I want to run with <code>eval()</code>?</strong></p>
  
  <p><strong>Edit:</strong> There are millions of individuals so writing to a file is not a great option.</p>
  
  <p><strong>Edit:</strong> I made a mistake. The eval() method is used only for expressions and not statements so using exec() is the correct approach</p>