Un/serialize functions?
Jim Meier
jim at dsdd.org
Tue Aug 6 01:56:43 EDT 2002
On Mon, 05 Aug 2002 16:11:03 -0600, d2002xx wrote:
> Hello.
>
> Is it possible to serialize a complete function/method, and
> unserialize without involving its source file?
Sort of. You can serialize their code objects with the marshall module:
s = marshall.dumps(some_func.func_code)
But that doesn't preserve any of the function or method attributes. These
are not hard to rebuild.
The trickiest problem is that it doesn't preserve the globals that the
function knows - you'll have to find a solution to that on your own.
-Jim
More information about the Python-list
mailing list