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

Steve Holden sholden at holdenweb.com
Tue Jun 26 09:28:12 EDT 2001


"Chris Tavares" <ctavares at develop.com> wrote in ...
> "David C. Ullrich" <ullrich at math.okstate.edu> wrote in ...
> > On Mon, 18 Jun 2001 08:19:30 -0700, Erik Max Francis <max at alcyone.com>
> > wrote:
> >
> > >Anders And wrote:
> > >
> > >> 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? I don't know what triggers it and thinking
> > >> back, I
> > >> think I have solved most of my problems with this message with a
major
> > >> code
> > >> rewrite.
> > >
> > >The error means just what it says:  You are calling a function with too
> > >many or too few arguments.  Why you're doing that exactly is something
> > >we couldn't tell you without code examples that actually give you the
> > >error.
> > >
> > >Only thing I can think of is that you've got a confusion with bound and
> > >unbound methods; if you call an unbound method (C.f where C is a class
> > >and f is a method), then you need to provide an instance of C as the
> > >first method (the implicit self method becomes explicit).
> >
> > Or he's not calling the function that he thinks he is, possibly
> > because of an "import *".
> >
> > (I refrained from guessing at first cuz I didn't want to leave
> > anything out. Is there a natural third possibility?)
> >
>
> The problem I still hit quite often is this:
>
> class Foo:
>     def MyMethod( x, y ):
>         pass
>
>
> foo = Foo()
> foo.MyMethod(1, 2)
>
> Boom! Called with three args, expected two.
>
This is one advantage of "self": using that name reminds you it's an implied
argument.

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list