KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Why doesn't Python allow modules to have a __call__ method? (Beyond the obvious that it wouldn't be easy to import directly.) Specifically, why doesn't using a(b) syntax find the __call__ attribute like it does for functions, classes, and objects? (Is lookup just incompatibly different for modules?) >>> 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
Tags (comma-separated)
Save Edits
Cancel