Conditional use of
So I have a class that remembers its instances based on an ID. When unpickling such an object there are two cases I'd like to handle:
__setstate__ should be called normally. __setstate__ on it. Please take a look at this class definition.
You will notice that currently I update only attributes that evaluate to False as a workaround.
I can think of two general strategies to solve this:
__getnewargs__ and attach some attribute that tells me whether to run __setstate__ or not. __call__ method was called from within pickle I could do the same. I do not know if it's possible to further interfere with the pickling machinery and I don't want to subclass the unpickler.
Thoughts, recommendations, completely different solutions? Thank you.
链接地址: http://www.djcxy.com/p/64824.html上一篇: UnpicklingError:NEWOBJ类参数不是一个类型对象
下一篇: 有条件地使用
