且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

可彬()在Python 2.6被重载就像十月()和十六进制()?

更新时间:2021-10-27 22:27:49

我觉得简单的答案是:不,斌()不能超载像十月()十六进制()

I think the short answer is 'No, bin() can't be overloaded like oct() and hex().'

至于为什么,答案必须位于与Python 3.0,它使用 __指数__ 超载十六进制()十月()斌(),并已删除了 __月__ __ __(十六进制)特殊功能完全。

As to why, the answer must lie with Python 3.0, which uses __index__ to overload hex(), oct() and bin(), and has removed the __oct__ and __hex__ special functions altogether.

所以,Python的2.6 斌()看起来非常像这真是一个Python 3.0的功能,一直没有,它的处事新的Python 3太多的考虑后移植方式,而不是旧的Python 2路。我还猜想,它不可能得到固定,即使它被认为是一个错误。

So the Python 2.6 bin() looks very much like it's really a Python 3.0 feature that has been back-ported without much consideration that it's doing things the new Python 3 way rather than the old Python 2 way. I'd also guess that it's unlikely to get fixed, even if it is considered to be a bug.