Hi I am showing a subsection of my code. I created a function(propertyValue) inside an object class(CashOnCashROI). I then created a function (calculator) outside the class. I instantiated the class as "rental" and then tried to use rental.propertyValue() to call the propertyValue function outside the class.
What I am trying to do is change the value for "self.globValue = int(value)" from the calculator() function but I keep getting: TypeError: propertyValue() takes 1 positional argument but 2 were given. I was hoping someone could help me explain what is going on, how to fix it, and if there is a better way to do this? I am just starting to learn about classes so I greatly appreciate it.
Here is the code, it should give the same TypeError.
class CashOnCashROI:
def propertyValue(self):
value = input('How much will you pay for the property?
')
while value.isdigit() == False:
value = input('Sorry, we need a number? What is the proposed property value?
')
print(f"Your current purchase value for the property is: {value}")
self.globValue = int(value)
def calculator():
rental = CashOnCashROI()
while True:
rental.propertyValue()
choice = input('<Other parameters asked here>, "Value" to change the property value.
')
if choice.lower() == "value":
xvalue = input('What would the new property value be?
')
rental.propertyValue(xvalue) ### How do I change the value here???
question from:
https://stackoverflow.com/questions/65867747/python-how-to-change-the-value-of-a-function-inside-a-class-from-an-outside-fun 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…