Consider the following example:
class A:
@property
def x(self): return 5
So, of course calling the a = A(); a.x
will return 5
But imagine that you want to be able to modify the property x.
This way, for example:
class A:
@property
def x(self, neg = False): return 5 if not neg else -5
And call it with a = A(); a.x(neg=True)
That will raise a TypeError: 'int' object is not callable
, that is quite normal, since our x
is evaluated as 5
.
So, I would like to know how one can pass more then one argument to the property getter, if it is possible at all.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…