我有一些python代码包装了一个类...这就是
的内容from functools import wraps
class MyClass(object):
def __init__(self, x):
self.x = x
def __call__(self):
return print(self.x)
def wrapper(class_):
@wraps(class_)
def myfunc():
c = class_(1)
return c()
return myfunc
func = wrapper(MyClass)
我试图稍后使用six.moves.cPickle
来解决这个问题...但我收到此错误消息。
> from six.moves import cPickle as pickle
> pickle.dumps(func)
Traceback (most recent call last):
File "<ipython-input-14-41b2e92407e0>", line 1, in <module>
pickle.dumps(func)
PicklingError: Can't pickle <function MyClass at 0x000000000A5AB1E0>: it's
not the same object as __main__.MyClass
任何人都知道这是否可行?我应该接近这是一种完全不同的方式吗?