"Full" object and class pickling?

Dave Brueck dbrueck at edgix.com
Fri Jan 12 15:11:36 EST 2001


The marshal module can do code. This may help a little, it's not class defs
but functions:

>>> def foo(a,b,c):
... 	print a + b + c
...
>>> foo(10,11,12)
33
>>> import marshal
>>> q = marshal.dumps(foo.func_code)
>>> def bar():
... 	pass
...
>>> bar.func_code = marshal.loads(q)
>>> bar(10,11,12)
33

Also, FWIW, it may be easier to have the remote side request the .py file
for an unknown class (ie - you send it an object it doesn't recognize, so it
comes back and asks for that module). Then you locally use imp module to
locate and read the module's .py, zlib to compress it, and then send it out
over the socket. But this might not be an option in your case...

-Dave
> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Stuart Stanley
> Sent: Friday, January 12, 2001 12:59 PM
> To: python-list at python.org
> Subject: "Full" object and class pickling?
>
>
>
> I am doing some experimenting with mobile objects.  I.E., python
> objects that physically migrate from process to process via some
> mechanism.  I had thought (c)pickle was my ticket, but pickle does
> not bring the _code_ with.  Does anyone know a mechanism to:
>
>   1) "pickle" the _complete_ object, including its byte-code?
>   2) "pickle" a class so I can create instances from it without using
>       imports?  I.E., I want to migrate the classes used in
> return values
>       from the above (#1) transported objects and use them to
> create objects
>       that can do things like compare against the return
> values from the
>       migratory objects...
>
> For a number of reasons I need to avoid doing imports in the
> "non-home"
> processes...
>
> Clues? Hints?  Complete packages that does all this already? ;)
>
> Thank you -- stuart
>
>
> --
>  "Computer Science is no more about computers than | Stuart Stanley
>  astronomy is about telescopes." - E. W. Dijkstra  | stuarts at cisco.com
>                                                    | Cisco
> Systems, inc
>                                                    | St Paul, MN
>                                                    | 612.578.6412
> --
> http://www.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list