File: class/Workbook/Examples/Lecture12/testpickle.txt

% python 
>>> from testpickle import *
>>> L = [0]
>>> D = {'x':0, 'y':L}
>>> table = {'A':L, 'B':D}            # L appears twice (D)
>>> saveDbase('myfile', table)        # serialize to file

% python
>>> from testpickle import *
>>> table = loadDbase('myfile')       # reload/unpickle
>>> print table
{'B': {'x': 0, 'y': [0]}, 'A': [0]}
>>> table['A'][0] = 1                 # change shared list
>>> saveDbase('myfile', table)

% python
>>> from testpickle import *
>>> print loadDbase('myfile')         # both L’s updated!
{'B': {'x': 0, 'y': [1]}, 'A': [1]}



[Home page] Books Code Blog Python Author Train Find ©M.Lutz