improved pickle

Amir Hadar amir at
Thu Mar 27 17:06:36 CET 2003

Hi All

First, to whom can I write suggestions for the next versions of python?

Anyway here is one:
I have improved the binary pickle module to be able to memorize existing

For example if you have a global instance that you don't want to store into
the persistence but you do want to restore references to it.
you should first memorize the instance and then dump some object.
When you want to unpickle then first memorize the global object with the
same key and then unpickle. All references to the global object that was
memorize in the dump will be restored to the global object that was
memorized in the load.

First Run of an application:
g = SomeGlobalInstance()  # instance 0x123456
c = SomeClass(g)  # c.Value = g
pickler.memo_inst(g ,"The global instance") #<-- NEW
Second Time the application runs:
g = SomeGlobalInstance()  # instance 0xFEFEFEFE
unpickler.memo_inst(g ,"The global instance")  #<-- NEW
c = unpickler.load()
assert c.Value == g

I have added them method memo_inst to the pickler and the unpickler. If
there is another way to do it please tell me.
I know that one can modify the memo dictionary but the structure of this
dictionary is not trivial.
If anyone want the source code please contact me.


More information about the Python-list mailing list