How to make my SWIG extension module work with Pickle?

后端 未结 3 1562
孤独总比滥情好
孤独总比滥情好 2020-12-15 08:18

I have an extension module for Python that uses SWIG as a wrapper and I try to serialize it with Pickle and I fail =)

  1. If anyone has a source of SWIG extension
3条回答
  •  囚心锁ツ
    2020-12-15 09:01

    I had to make a minor change to the accepted answer to make it work for my case. Since the initialization function of my class has some input arguments, I had to add an extra argument *arg to the C.__init(self) function, like so:

        class PickalableC(C, PickalableSWIG):
            def __init__(self, *args):
                self.args = args
                C.__init__(self, *args)
    

    Maybe this is helpful for someone. I hope it is not too trivial.

    I posted it as an answer since I cannot comment and learned it is not something you edit a post for.

提交回复
热议问题