Pickling dynamically generated classes?

后端 未结 6 779
野性不改
野性不改 2020-12-24 11:48

I\'m using type() to dynamically generate classes that will ultimately be pickled. The problem is that the un-pickling process needs the definition of the class

6条回答
  •  -上瘾入骨i
    2020-12-24 12:17

    Well, for the posterity; works with cloudpickle

    import cloudpickle
    
    class Foo(object):
        pass
    g=type('Goo',(Foo,),{'run':lambda self,x: 2*x } )()
    cloudpickle.dumps(g)
    

提交回复
热议问题