Python: can't pickle module objects error

后端 未结 4 1800
不思量自难忘°
不思量自难忘° 2020-12-16 13:24

I\'m trying to pickle a big class and getting

TypeError: can\'t pickle module objects

despite looking around the web, I can\'t e

4条回答
  •  时光说笑
    2020-12-16 13:48

    I can reproduce the error message this way:

    import cPickle
    
    class Foo(object):
        def __init__(self):
            self.mod=cPickle
    
    foo=Foo()
    with file('/tmp/test.out', 'w') as f:
        cPickle.dump(foo, f) 
    
    # TypeError: can't pickle module objects
    

    Do you have a class attribute that references a module?

提交回复
热议问题