title: Calling a function in python with pointer address
body: <p>I have a simple function I want to call in two separate program executions. The first time I run the program it saves the function pointer into a file:</p>
  
  <pre><code>import cPickle
  
  def test():
      pass
  
  def main():
      a = test
      pFile = open('test.txt', 'wb')
      cPickle.dump(a, pFile)
      pFile.close()
  </code></pre>
  
  <p>The second time I want to load the file and execute the function saved in the object:</p>
  
  <pre><code>import cPickle
  
  def test():
      pass
  
  def main():
      pFile = open('test.txt', 'rb')
      a = cPickle.load(pFile)
      pFile.close()
      a() 
  </code></pre>
  
  <p>Note that with cPickle, this works, which is a bit odd, since I figured this is basically a pointer to the function and that this would change at runtime? When I print 'a', it gives me something like :function test at 0x0351C170:. </p>
  
  <p>So I guess my first question is, why does this work, even though the reference address should change at runtime?</p>
  
  <p>And my second question would be, if it does not change/or it's irrelevant somehow, how can I execute the function just from having the string: :function test at 0x0351C170:. e.g. something like:</p>
  
  <pre><code>def test():
      print 'test'
  
  a = test
  a()          #outputs: 'test'
  
  b = str(a)   #&lt;function test at 0x03509170&gt;
  eval(b)()    #error
  </code></pre>