Python:无法腌制模块对象错误 [英] Python: can't pickle module objects error

查看:72
本文介绍了Python:无法腌制模块对象错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给一个大班上课泡菜,然后开始学习

I'm trying to pickle a big class and getting

TypeError:无法腌制模块对象

TypeError: can't pickle module objects

尽管在网上四处张望,但我仍无法确切地知道这是什么意思.而且我不确定是哪个module object引起了问题.有办法找到罪魁祸首吗?堆栈跟踪似乎没有指示任何内容.

despite looking around the web, I can't exactly figure out what this means. and I'm not sure which module object is causing the trouble. is there a way to find the culprit? the stack trace doesn't seem to indicate anything.

推荐答案

我可以通过以下方式重现错误消息:

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

您是否具有引用模块的class属性?

Do you have a class attribute that references a module?

这篇关于Python:无法腌制模块对象错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆