Pickling: how do I ask an intelligent question?

Aahz Maruch aahz at netcom.com
Wed Sep 22 19:48:57 EDT 1999


In article <7sblq6$q6$1 at nnrp1.deja.com>,
Gustin Kiffney  <kiffney at my-deja.com> wrote:
>
>but in looking at the pickle module it seems that I could somehow
>package up an 'object' and send all that to the NT python server,
>who could then unravel it and send back pickled results.  This seems
>neater and more elegant, but maybe that's because I don't have any
>notion about how you really do that.  I actually don't understand what
>an 'object' is yet - some innate stupidity about abstractions - and
>I can't figure out how I'd construct this thing.  I mean, I can get
>pickle to pickle a list or whatever to a file, and get it back out, but
>how would you construct and pickle a collection of information like
>named parameters, strings, data tuples, etc and then USE it on the
>other side, modify it, fill in the data,and send it back?

An object in the sense that you're using it is an instance of a class
definition.  So what you need to do is define a class with the
appropriate data members (which may include lists and dicts), then
instantiate it, update it, pickle it, and send it to the server.  The
server just uses the object like any other class instance and sends it
back.  As long as you have imported the appropriate modules/packages on
both sides, you're all set.

NOTE: you must use the exact same import method on both sides, because
the pickled object expects the same namespace setup.  (I.e., can't use
"import foo" one side and "from foo import *" on the other.)
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>      http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6  (if you want to know, do some research)




More information about the Python-list mailing list