如何实现等效的 __getattr__在类,模块上于a?
例
当调用模块的静态定义的属性中不存在的函数时,我希望在该模块中创建一个类的实例,并使用与该模块上的属性查找失败相同的名称调用该方法。
class A(object):
    def salutation(self, accusative):
        print "hello", accusative
# note this function is intentionally on the module, and not the class above
def __getattr__(mod, name):
    return getattr(A(), name)
if __name__ == "__main__":
    # i hope here to have my __getattr__ function above invoked, since
    # salutation does not exist in the current namespace
    salutation("world")这使:
matt@stanley:~/Desktop$ python getattrmod.py 
Traceback (most recent call last):
  File "getattrmod.py", line 9, in <module>
    salutation("world")
NameError: name 'salutation' is not definedsalutation存在于全局或本地命名空间中(上面的代码正在尝试这样做),还是要在模块上进行点访问时动态查找名称?这是两件事。
                __getattr__Python 3.7支持模块上的on