Python: Can't pickle type X, attribute lookup failed

前端 未结 4 1097
臣服心动
臣服心动 2020-11-28 10:30

I am trying to pickle a namedtuple:

from collections import namedtuple
import cPickle

class Foo:

    Bar = namedtuple(\'Bar\', [\'x\', \'y\'])         


        
4条回答
  •  悲哀的现实
    2020-11-28 11:04

    The solution here is to move your named tuple definition to the module level, then pickle works. A detailed answer is provided here:

    How to pickle a namedtuple instance correctly

提交回复
热议问题