Python:检测重新定义?
我正在寻找一种方法来检测 python 函数或类是否正在被重新定义,或者即使它被定义了两次并且一个定义删除了另一个定义。
这可以通过反射来完成吗?
也许是通过函数(或类)本身以某种方式?
I'm looking for a way to somehow detect if a python function or class is being redefined or even only if it is defined twice and one definition erases the other.
Can this be done with reflection somehow?
Maybe by the function (or class) itself somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
类的重新定义对原始类没有任何作用,它只是将一个全新的类分配给相同的名称。检查很简单 - 只需保存原始文件,然后查看该名称是否仍然引用它即可。
Redefinition of a class does nothing to the original class, it just assigns a whole new class to the same name. Checking is easy – just save the original, and see if the name still refers to it.