python pickle.dumps AssertionError

后端 未结 1 1992
刺人心
刺人心 2021-01-06 04:20

I\'m trying to pickle a class instance containing two lists of another instances. The instances in the two lists have attributes that refer instances of each other. Here are

相关标签:
1条回答
  • 2021-01-06 04:57

    There are some kinds of data the older pickle protocol cannot handle. To solve your problem, use pickle.HIGHEST_PROTOCOL

    >>> p = pickle.dumps(g)
      File "/usr/lib/python2.6/pickle.py", line 244, in memoize
        assert id(obj) not in self.memo
    AssertionError:
    >>> p = pickle.dumps(g, pickle.HIGHEST_PROTOCOL)
    >>> # No problem!
    
    0 讨论(0)
提交回复
热议问题