Can I mark variables as transient so they won't be pickled?

According to the Pickle documentation you can provide a method called getstate__() which returns something representing the state you want to have pickled (if it isn't provided pickle uses thing. __dict ). So, you can do something like this.

According to the Pickle documentation, you can provide a method called __getstate__(), which returns something representing the state you want to have pickled (if it isn't provided, pickle uses thing. __dict__). So, you can do something like this: class Thing: def __getstate__(self): state = dict(self.

__dict__) del state'cachedBar' return state This doesn't have to be a dict, but if it is something else, you need to also implement __setstate__(state).

One could generalize this facility using custom data descriptors that would store things under self. _transient, and then __getstate__ could be written just once to ignore _transient. But that's likely overkill unless the code base is doing this a lot.

– Luke Maurer Jun 11 at 1:28 Ahh, thanks, dude! I kept on googling for something to attach or denote against actual variables to exclude them, I didn't think to look for a method to include them :S – SCdF Jun 11 at 3:26.

Implement __getstate__ to return only what parts of an object to be pickled.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions