腌制__setstate__和__getstate__不上课 [英] Pickling __setstate__ and __getstate__ not invoking on class

查看:127
本文介绍了腌制__setstate__和__getstate__不上课的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个属于多重继承的类,并且__getstate____setstate__函数从未在子类上调用.

I have a class that is part of multiple inheritance, and the __getstate__ and the __setstate__ functions never get called on the child class.

class BaseGeometery(dict):
    pass

@add_metaclass(GeometryFactory)
class Geometry(BaseGeometry): 
    pass

class Point(Geometry): 
    def __init__(self, iterable=None):
        # initialize and call super()
        pass 

    def __setstate_(self, d):
          print(d)

    def __getstate__(self):
         print('in get state')

有什么主意我做错了吗?

Any ideas what I'm doing wrong?

推荐答案

您的def __getstate__(self):,应该返回一些内容.

Your def __getstate__(self):, should return something.

阅读:处理有状态对象

这篇关于腌制__setstate__和__getstate__不上课的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆