我有以下代码:
class TransactedProperty:
def __init__(self, address, propertyValue):
self._address = address
self._propertyValue = propertyValue
@property
def address(self):
return self._address
@property
def propertyValue(self):
return self._propertyValue
@propertyValue.setter
def propertyValue(self, newpropertyValue):
self._propertyValue = newpropertyValue
def __str__(self):
return f'Property Address: {self._address} Value: ${self._propertyValue}'
我试图将propertyValue传递给另一个类。
class Transaction:
_nextTransactionId = 1
def __init__(self, transactionId, TransactedProperty, Buyer):
self._transactionId = transactionId
self._TransactedProperty = TransactedProperty
self._Buyer = Buyer
# self._ABSDRate = Buyer.getABSDRate
# self._ABSDRate = ABSDRate
Transaction._nextTransactionId += 1
#ItemDelivery()
@property
def Buyer(self):
return self._Buyer
@property
def TransactedProperty(self):
return self._TransactedProperty
然后做比较:
def BSDPayable(self):
newPropertyValue = 0
toAdd = 0
propertyValue = TransactedProperty.propertyValue
while True:
if propertyValue> 180000:
toAdd = 180000 * 0.1
newPropertyValue = propertyValue - 180000
if newPropertyValue > 180000:
toAdd2 = 180000 * 0.2
BDS = toAdd + toAdd2
newPropertyValue = newPropertyValue - 180000
if newPropertyValue > 640000:
toAdd3 = 640000 * 0.3
BDS = toAdd + toAdd2 + toAdd3
newPropertyValue = newPropertyValue - 640000
if newPropertyValue > 0:
toAdd4 = newPropertyValue * 0.4
BDS = toAdd + toAdd2 + toAdd3 + toAdd4
else:
break
return BDS
然后致电:
我在类TransactedProperty下传递了propertyvalue 345678885,因此在调用它进行计算时应该传递过来。
def main():
p1 = TransactedProperty('Oxley Road', 345678885)
错误代码:
'property'和'int'实例之间不支持'>'
不断出现,有什么建议吗?
最佳答案
使用您的实际代码,您正在尝试比较属性对象:
propertyValue = TransactedProperty.propertyValue
propertyValue
>>> <property object at 0x7f190c1db410>
您需要正确初始化:
propertyValue = TransactedProperty("id", 123456)
propertyValue.propertyValue
>>> 123456
关于python - 'property'和'int'实例之间不支持'>',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58889141/