[C++-sig] pickling new-style classes object
dimour at mail.ru
Wed Oct 20 14:22:51 CEST 2004
Is it possible to customize pickling for class objects?
or these are pickled only by name using default implementation.
I need to save and restore custom class definition in different Python
sessions. For example:
def __init__(cls, name, bases, dict):
super(Prototype, cls).__init__(name, bases, dict)
__metaclass__ = Prototype
def __init__(self, name):
self.__name__ = name
If I define new class
class New(C): pass
New.a = 35
New.b = 'string'
and new instance of 'New':
x = New('New')
And trying to save 'New' and 'x':
file = open('pickle_New.txt', 'w')
file = open('pickle_x.txt', 'w')
I have only 'x' state saved.
__getstate__ and __setstate__ are not called for class instances(New).
What is the problem? Is there another way to resolve this problem?
More information about the Cplusplus-sig