So, I am pickling an object from within the class ( see How to pickle yourself ) :
def save(self, path):
f = open(path, 'wb')
pickle.dump(self, f)
f.close()
@classmethod
def load(cls, path):
f = open(path, 'rb')
obj = pickle.load(f)
f.close()
return obj
which works fine. But there is one large attribute I don't want to pickle in most cases. How can I do that? Should look somehow like this:
def save(self, path, without_attr_x =True):
f = open(path, 'wb')
if(without_attr_x):
#somehow remove attr_x from the pickling
# I could do self.attr_x = None but this deletes attr_x from the running instance as well
pickle.dump(self, f)
f.close()