Aargh! Function takes exactly x arguments, y given..

Georg Lohrer GeorgLohrer at gmx.de
Mon Jun 18 09:51:04 EDT 2001


On Mon, 18 Jun 2001 14:26:13 +0200, "Anders And" <someone at spam.com>
wrote:

>Hi!
>
>I am a happy pythoneer using a combination of C++ and Python for my everyday
>work.
>Usually, debugging is easy but every now and then, I get the "function takes
>exactly x arguments, y given" error message, clearly due to some other
>problem than what Python thinks. Does anybody have any experience with this
>particular error message? 

Of course everybody who write Python code will come into contact with
these messages. But what's up? The messages stands for itself. You
have not passed the correct amount of arguments to a
function/method-call, don't you. So, fix your amount of arguments and
you'll get into the right way.

But pay attention. It's somewhat confusing that calling
classes-methods, always the passed 'self'-parameter counts as well.
Look at this:

class foo:
  def foo_method1(self, p1, p2):
    pass

f = foo()
f.foo_method(1)

will yield: "function takes exactly 3 parameters, 2 given".  If
writing code like:

def foo_function(p1, p2):
  pass

foo_function(1)

will yield: "function takes exactly 2 parameters, 1 given".

Ciao, Georg



More information about the Python-list mailing list