Re: marshall type but builds stringobj??

Guido.van.Rossum@cwi.nl
Sat, 16 Jan 1993 00:28:52 +0100

me:
>> You can already send Python objects as strings across networks using
>> repr() or `` and eval(), but you're right that marshal would be more
>> efficient. (Though not more general -- the same objects for which
>> eval(`x`) fails also cannot be load()ed by marshal.)

Lance:
>This may be true, but You cannot send the following easily using repr()
>or `` or eval():
>
> (0,'This is a test',func)
>
>Where func is a code object that should be sent and executed on the
>remote machine (where 'func' did NOT exist on the remote machine).

And indeed you can't marshal function objects either. The reason is
that a function object contains a reference to the module in which it
is declared, because it *may* need global variables there. The same
module may not exist at the remote end, and even if it exists the
effect would not be the same, since the values of the global variables
in that module may differ. This is not likely to change. Note that
even if the function *doesn't* reference global variables it still
contains a pointer to the module, since the parser isn't powerful
enough to detect this.

If you really need to pass a function to a remote machine, you are
better off sending the function's source code.

"Code objects", the internal "compiled" form of Python code, can be
marshalled, however there is no way to call a code object (the
implementation of "import" uses code objects). (Maybe there should be
a way?)

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>