Extracting pickle from Python

"Martin v. Löwis" martin at v.loewis.de
Mon May 16 17:58:41 EDT 2005


Philippe C. Martin wrote:
> How would one go about extracting the pickle module from Python (ex: to make
> a .a or a .dll) ?

Pickle relies heavily on Python, so you most likely have to take the
rest of Python as well when trying to integrate pickle elsewhere?

Are you looking for pickle or cPickle? pickle.py is written in Python,
so you need a full Python interpreter to run it. cPickle is written
in C, so you could go away with less than a full interpreter, but
it still calls a lot of Python interpreter functions.

To integrate a Python interpreter, see the "Embedding and Extending"
manual, in particular the "embedding" part. Essentially, you need to
link with pythonxy.dll/libpythonxy.a.

If you want a Python-free implementation of pickle, you best rewrite
it yourself. The core of pickle is fairly easy. The tricky part is
the extensibility: During unpickling, arbitrary Python functions can
be invoked to reconstruct objects, and arbitrary classes can be
instantiated, so you need to emulate constructors for all types
that may be present in your pickle files.

Regards,
Martin



More information about the Python-list mailing list