title: Is there an easy way to pickle a python function (or otherwise serialize its code)?
body: <p>I'm trying to transfer a function across a network connection (using asyncore). Is there an easy way to serialize a python function (one that, in this case at least, will have no side effects) for transfer like this?</p>
  <p>I would ideally like to have a pair of functions similar to these:</p>
  <pre><code>def transmit(func):
      obj = pickle.dumps(func)
      [send obj across the network]
  
  def receive():
      [receive obj from the network]
      func = pickle.loads(s)
      func()
  </code></pre>