从python的腌制中排除对象的字段 [英] Exclude object's field from pickling in python

查看:60
本文介绍了从python的腌制中排除对象的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想避免在类的实例中腌制某些字段. 目前,在腌制之前,我只是将这些字段设置为无",但是我想知道是否还有更优雅的解决方案?

I would like to avoid pickling of certain fields in an instance of a class. Currently, before pickling I just set those fields to None, but I wonder whether there's more elegant solution?

推荐答案

有一个示例 ,它可以解决__getstate____setstate__的问题.

There is an example in the docs which solves your problem with __getstate__ and __setstate__.

这篇关于从python的腌制中排除对象的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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