gpt4 book ai didi

python - super() 行尾终止符

转载 作者:行者123 更新时间:2023-11-28 22:44:22 24 4
gpt4 key购买 nike

我刚刚一直在看 Super considered super Raymond Hettinger 的演讲。在其中,他描述了 super() 如何在线调用下一个类。他使用显示方法解析顺序的 help() 方法直观地演示了这一点。

在演讲快结束时,他描述了在方法解析行末尾需要一个 super 停止器类。我用谷歌搜索了这个术语,但没有发现任何东西,所以我不清楚他在这里的确切含义 - 这个塞子类在实践中是如何工作的?

最佳答案

只是链中的方法使用super() 调用下一个方法。通常这些位于层次结构中的基类上。

毕竟,如果 MRO 链中没有要调用的下一个方法,您会收到错误消息,因为一开始就没有要查找的下一个方法。

Raymond 非常明确地说明了这一点;视频转录:

You put a stopper object at the end; not object, you can create an object, call it Root, and put it in, and all it is something that has the method of interest; pass it along but doesn't actually call super(). Somebody at the end of the chain shouldn't call super().

关于python - super() 行尾终止符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29587925/

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