Code marshalling question.

brueckd at tbye.com brueckd at tbye.com
Tue Oct 8 12:21:08 EDT 2002


On Tue, 8 Oct 2002 sismex01 at hebmex.com wrote:

> I've had this question for a while.  Is there a way to marshal
> a segment of code into a string, which can then be transported
> (via whatever method), such that the code segment can be
> unmarshalled later and executed?

The marshal module can marshal code objects:

def f(x):
  print x

import marshal
marshal.dumps(f.func_code)

But IMO an even better approach is to just send the .py file, save it to 
some local file, and then import that module.

-Dave





More information about the Python-list mailing list