title: How do you get Python to write down the code of a function it has in memory?
body: <p>When I pass the options in the program (a computational biology experiment) I usually pass them through a .py file.<br>
  So I have this .py file that reads like:</p>
  
  <pre><code>starting_length=9
  starting_cell_size=1000
  LengthofExperiments=5000000
  </code></pre>
  
  <p>Then I execute the file and get the data. Since the program is all on my machine and no one else has access to it, it is secure in a trivial way.<br>
  I can also write a similar file very easily:</p>
  
  <pre><code>def writeoptions(directory):
      options=""
      options+="starting_length=%s%s"%(starting_length,os.linesep)
      options+="starting_cell_size=%s%s"%(starting_cell_size,os.linesep)
      options+="LengthofExperiments=%s%s"%(LengthofExperiments,os.linesep)
  ...
      open("%s%soptions.py"%(directory,os.sep),'w').write(options)
  </code></pre>
  
  <p>I want to pass a function as one of the parameters:</p>
  
  <pre><code>starting_length=9
  starting_cell_size=1000
  LengthofExperiments=5000000
  
  def pippo(a,b):
      return a+b
  functionoperator=pippo
  </code></pre>
  
  <p>And of course in the real experiment the function pippo will be much more complex. And different from experiment to experiment.</p>
  
  <p>But what I am unable to do is to write the function automatically. In short I don't know how to generalise the writeoptions function to keep on writing the options, if one of the options is a function. I could of course copy the original file, but this is inelegant, inefficient (because it contains a lot of extra options that are not being used), and generally does not solve the question.</p>
  
  <p>How do you get python to write down the code of a function, as it writes down the value of a variable?</p>