Pickle with custom classes

后端 未结 2 1317
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 17:42

Suppose I have a simple python class definition in a file myClass.py

class Test:
    A = []

And I also have two test scripts. The first scr

2条回答
  •  既然无缘
    2020-12-05 18:35

    This is an old question, if you see it now you probably want to set __getstate__ and __setstate__ of your class so pickle would know how to dump and load your defined class.

    See examples here.

    If your class is simple (e.g. only have ints and strings as members and any method) it should be pickalable automatically.

提交回复
热议问题