main():请参阅注释中提到的结果的函数。*一般注意事项:当Class()有一个attribute包含例如str->时,@propery.setter一旦设置就会验证。
但是,当我将 a 存储dictionary在 中时Class.attribute,@property.setter如果我直接设置 a ,则 My 不起作用key : value
class CoinJar():
def __init__(self):
self._priceDict = {'current' : 0.0, 'high' : 0.0, 'low' : 0.0}
self.klines = {}
self.volume = {}
def __str__(self):
return f'\n\U0001F36A'
@property
def priceDict(self):
return self._priceDict
@priceDict.setter
def priceDict(self, priceDict):
print('setting price')
try:
newPrice = float(priceDict.get('current'))
except ValueError as e:
print(f'Input cannot be converted to float {e}')
# Exceptions …Run Code Online (Sandbox Code Playgroud)