Newbie question: Strange TypeError
Adrien Di Mascio
Adrien.DiMascio at logilab.fr
Mon Jul 7 03:10:07 EDT 2003
On Mon, Jul 07, 2003 at 04:04:32AM +0000, Tim Isakson wrote:
> Howdy,
Hi,
>
>
> def HandleInput(self, input):
> if self.results.GetValue() == "0":
> return input
> elif newVal == True:
> return input
> else:
> tmpVal = self.results.GetValue() + input
> return tmpVal
>
> def OnButton1(self,e):
> tmpVal = self.HandleInput(self, "1")
> self.results.SetValue(tmpVal)
> The call to HandleInput is made, but I get the following error:
>
> Calling HandleInput(self, '1')
> Traceback (most recent call last):
> File "pycalc.py", line 115, in OnButton1
> tmpVal = self.HandleInput(self, "1")
> TypeError: HandleInput() takes exactly 2 arguments (3 given)
> So far as I can tell, the offending call *IS* calling HandleInput with 2
> arguments, but the interpreter obviously thinks different, and I'm at a
> loss as to why that might be.
Well, your script *IS* calling HanlderInput with 3 arguments since
there is the 'hidden' object instance as first argument. You must not
explicitly pass the 'self' argument, Python will do it for you, so
just call :
tmpVal = self.HandleInput("1")
Hope this helps.
Cheers,
--
Adrien Di Mascio
LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org
More information about the Python-list
mailing list