bit of an issue with a function I’m writing for adding and subtracting a value located within a class.
I’m trying to pass a value that I’ve read in from a csv to my add function. This value is a decimal value (e.g. 500.00) I’ve tried eliminating the trailing 0’s to make it just 500, this didn’t work either. I keep getting:
TypeError: add() takes exactly one argument (two given).
Even though I have a print statement confirming its only trying to pass in the 500.
Here’s my function:
def add(amount):
self.total = self.total + amount
It’s being called by v.add(i) Even if I set i to an arbitray integer value it still results in the same error. I am relatively inexperience with python, so perhaps there is something simple I’m missing here. Thanks.
When you call an object method, it implicitly passes a reference to the object – so calling
v.add(something)actually callsMyclass.add(v, something).Voila – two parameters, when you told it to only expect one…