您好,我的任务很简单,但我又被卡住了:
如何将类中的变量用于描述符?
我有commission
来自父类的变量,我需要在调用时将它用于描述符set
:self.amount = int(amount) * int(commission)
我怎样才能做到这一点?
谢谢!
完整代码如下:
class Value():
def __init__(self):
return
def __get__(self, obj, obj_type):
return self.amount
def __set__(self, obj, amount, commission):
self.amount = int(amount) * int(commission)
class Account:
def __init__(self, commission):
self.commission = commission
amount = Value(self.commission)
new_account = Account(0.1)
new_account.amount = 100
print(new_account.amount)