1

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?

none
  • 1,187
  • 2
  • 13
  • 17
  • You might want to take look at [this question](http://stackoverflow.com/questions/1253528) and [this one](http://stackoverflow.com/questions/573569). Seems you'll be better off using an external library. – kyrill Apr 02 '17 at 21:13

0 Answers0