gpt4 book ai didi

python - __reduce__ 和 __reduce_ex__ 有什么区别?

转载 作者:IT老高 更新时间:2023-10-28 21:18:11 26 4
gpt4 key购买 nike

我知道这些方法是用于 pickle/解酸的,与 reduce 内置函数无关,但 2 有什么区别,为什么我们都需要?

最佳答案

The docs这么说

If provided, at pickling time__reduce__() will be called with noarguments, and it must return either astring or a tuple.

另一方面,

It is sometimes useful to know theprotocol version when implementing__reduce__. This can be done byimplementing a method named__reduce_ex__ instead of__reduce__. __reduce_ex__, when itexists, is called in preference over__reduce__ (you may still provide__reduce__ for backwardscompatibility). The __reduce_ex__method will be called with a singleinteger argument, the protocolversion.

在紧握的手上,Guido says这是一个可以清理的区域。

关于python - __reduce__ 和 __reduce_ex__ 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/150284/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com