My original problem is to check within a function if a module function is callable.Therefore the same function can be called in several different ways.
是的,但它是同一个物体。您只需使用f is g来测试f和{}是否是同一个对象。在
更新:为什么需要使用唯一的ID?说真的,别这样。您使用is进行身份测试,使用__hash__方法定义适用的哈希函数。在It would be fantastic to have the actual call alias to it.
不知道你的意思,但我想你只是希望它永远是一个物体。已经是了。在mod is mathematical function and sys.mod returns a list of loaded modules, but python (2.7) does not complain to from sys import mod. I find this a bit awkward?
那就别那么做了。你知道import ... as语法。另外,默认情况下,mod不在全局命名空间中(操作符%用于此)。在
最后,python确实抱怨您的导入行:>>> from sys import mod
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name mod
(感谢金多尔指出这一点)。在