This module does not copy types like module, method, stack trace, stack frame, file, socket, window, array, or any similar types. It does “copy” functions and classes (shallow and deeply), by returning the original object unchanged; this is compatible with the way these are treated by the pickle module.
可能的解决方法是使用@property装饰器而不是属性。
例如,这应该有效:
import numpy as np
import pickle
class Foo():
@property
def module():
return np
foo = Foo()
with open('test.out', 'wb') as f:
pickle.dump(foo, f)
我可以这样复制错误消息:
是否有引用模块的类属性?
Python无法pickle模块对象是真正的问题。有什么好理由吗?我不这么认为。模块对象不可访问导致了python作为并行/异步语言的脆弱性。如果要pickle模块对象,或者python中的几乎任何对象,那么使用
dill
。在这里获取
dill
:https://github.com/uqfoundation/dill根据文件:
如您所见,模块不在列表中。注意,这在使用
deepcopy
时也是正确的,而且不仅适用于pickle
模块,如deepcopy
文档中所述:可能的解决方法是使用
@property
装饰器而不是属性。 例如,这应该有效:相关问题 更多 >
编程相关推荐