I have some python code that wraps a class... something along the lines of this
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)
I'm trying to later pickle this using six.moves.cPickle
... but I get this error message.
> 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
Anyone know if this is possible? Should I just approach this is a totally different way?