【发布时间】:2011-08-08 14:34:30
【问题描述】:
考虑以下示例:
class A:
@property
def x(self): return 5
所以,当然调用a = A(); a.x 将返回5
但假设您希望能够修改属性 x。
这样,例如:
class A:
@property
def x(self, neg = False): return 5 if not neg else -5
并使用a = A(); a.x(neg=True) 调用它
这将引发 TypeError:'int' object is not callable,这很正常,因为我们的 x 被评估为 5。
所以,如果可能的话,我想知道如何将多个参数传递给属性 getter。
【问题讨论】:
标签: python properties language-features