【发布时间】:2019-08-24 16:51:05
【问题描述】:
假设你有
class c:
pass
print(c.__call__)
output: <method-wrapper '__call__' of type object at 0x0000023378F28DC8>
我的问题是,如果定义了 __call__,我将无法获得相同的输出
像这样:
class c:
__call__ = lambda self: None
print(c.__call__)
output: <function c.<lambda> at 0x000002337A069B70>
type.__getattribute__(c, '__call__') 都不起作用
总结一下,我想在两个示例中都首先输出
有可能吗(我猜是通过一些元编程)
【问题讨论】:
标签: python-3.x class metaprogramming