Code marshalling question.
Lexy Zhitenev
zhitenev at cs.vsu.ru
Tue Oct 8 11:32:58 EDT 2002
Probably you need a 'pickle' or 'cPickle' module?
'marshal' module in python cannot save classes, but pickle does can.
I think the following implementation may do good:
>>> import cPickle, UserDict
>>> class ObjDict(UserDict.UserDict):
... def __getitem__(self, key):
... return cPickle.loads(self.data[key])
... def __setitem__(self, key, value):
... self.data[key]=cPickle.dumps(value, 1) # true value (1) means binary
format, false - text only
For Python 2.2 implementation may vary: inherit from 'dict' builtin class
and blah-blah-blah
After this you can store objects in this class like in ordinary dictionary.
Dictionary values contain pickled version of your arbitrary data (it cannot
be modules). Then you can take this string representation where you like.
Lexy Zhitenev at cs.vsu.ru
More information about the Python-list
mailing list