Pickle all attributes except one

后端 未结 6 933
野性不改
野性不改 2021-01-17 07:51

What is the best way to write a __getstate__ method that pickles almost all of an object\'s attributes, but excludes a few?

I have an object wi

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 08:10

    You could always just remove the bad items:

    def __getstate__(self):
        state = self.__dict__
        del state[...]
        return state
    

提交回复
热议问题