遵循PEP-562:
https://www.python.org/dev/peps/pep-0562/
现在可以为模块定义属性。不幸的是,一些内置组件还没有适应这个新特性。在以下代码中:
@property
def lazyFn():
return 3
v = lazyFn
v
理想情况下v
应该具有属性值3。不幸的是,@property
的当前实现只产生以下结果:
<property at 0x7f3e703eae30>
我该如何修复它,使其按预期运行?或者,在哪里可以找到具有适当实现的替换?你知道吗
Tags:
我不敢相信答案会有多简单(而且这不是一个内置或插销),不需要反射、模块、setattr或PEP-562。我只需要定义一个装饰者:
要测试它:
请纠正我,如果这个执行是有缺陷的
相关问题 更多 >
编程相关推荐