减少和减少的区别是什么?

2024-06-16 13:33:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道这些方法是用于pickling/unpickling的,与reduce内置函数没有关系,但是2之间的区别是什么?为什么我们需要两者?


Tags: 方法函数reduce关系内置区别picklingunpickling
2条回答

The docs说吧

If provided, at pickling time __reduce__() will be called with no arguments, and it must return either a string or a tuple.

另一方面

It is sometimes useful to know the protocol version when implementing __reduce__. This can be done by implementing a method named __reduce_ex__ instead of __reduce__. __reduce_ex__, when it exists, is called in preference over __reduce__ (you may still provide __reduce__ for backwards compatibility). The __reduce_ex__ method will be called with a single integer argument, the protocol version.

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

__reduce_ex____reduce__本应但从未成为的。__reduce_ex__的工作方式与__reduce__类似,但pickle协议已通过。

相关问题 更多 >