为什么Python不允许模块有__call__?(显而易见的是,直接导入并不容易.)具体来说,为什么不使用a(b)语法找到__call__属性,就像它对函数,类和对象一样?(模块的查找是否不相同?)
>>> print(open("mod_call.py").read())
def __call__():
return 42
>>> import mod_call
>>> mod_call()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>> mod_call.__call__()
42
Run Code Online (Sandbox Code Playgroud)