I am writing a class that does some data processing. I initiated the class and did some processing then pickled the results. the problem is that I added new methods to the class and loaded the pickled objects but I couldn't apply the new methods to the unpickled ones.
For example, This is my class
class Play(ABC):
def __init__(self, data):
self.data = data
@abstractmethod
def method(self):
pass
class M(Play):
def __init__(self, data):
super().__init__(data)
def method(self):
self.corr = np.corrcoef(self.data)
I did some processing
mat = np.random.rand(102, 641)
s = M(mat)
s.method()
and pickled them using dill
def save_object(obj, filename):
with open(filename, 'wb') as output:
dill.dump(obj, output, dill.HIGHEST_PROTOCOL)
save_object(s, 'file.pkl')
then, I added new methods to the class and unpickled the file to apply those methods but I couldn't
class Play(ABC):
def __init__(self, data):
self.data = data
@abstractmethod
def method(self):
pass
class M(Play):
def __init__(self, data):
super().__init__(data)
def method(self):
self.corr = np.corrcoef(self.data)
def new(self):
# pass
self.q = self.corr.shape
def load_object(filename):
with open(filename, 'rb') as input:
obj = dill.load(input)
return obj
obj = load_object('file.pkl')
obj.new()
and I get this result
AttributeError: 'M' object has no attribute 'new'
How can I fix that?