Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3835

Re: Argument count mismatch

From Steven D'Aprano <steve+comp.lang.python@pearwood.info>
Subject Re: Argument count mismatch
Newsgroups comp.lang.python
References <ac20c08e-6957-4836-9319-e668a8da8112@q30g2000vbs.googlegroups.com>
Date 2011-04-22 01:43 +0000
Message-ID <4db0dd4b$0$29978$c3e8da3$5496439d@news.astraweb.com> (permalink)
Organization Unlimited download news at news.astraweb.com

Show all headers | View raw


On Thu, 21 Apr 2011 12:33:09 -0700, RVince wrote:

> I am getting the following:
> 
> Error - <type 'exceptions.TypeError'>: cmseditorlinemethod() takes
> exactly 2 arguments (1 given)
> 
> When I make the following call:
> 
> http://localhost/eligibility/cmseditorlinemethod/474724434

That's not a call, that's a URL. It's also a link to localhost, which is 
*your* computer and not visible to us.

How about actually showing us the *actual call* you make? Cut and paste 
the line of code that calls cmseditorlinemethod, showing the arguments.

My *guess* is that you're calling it without providing any arguments:

instance.cmseditorlinemethod()

Python automatically injects the `self` argument, but it requires two: 
self and ssn:

> def cmseditorlinemethod(self, ssn):
[...]


An alternative explanation: you don't use `self` in the body of 
cmseditorlinemethod. Possibly cmseditorlinemethod is actually a stand-
alone function rather than a method, and you are calling it like this:

cmseditorlinemethod(ssn)

but you have mistakenly declared the function to take two arguments.

Really, the error message is quite explicit in your problem: you have one 
argument given, but two arguments are required. The only subtlety is that 
for method calls, the `self` argument is automatically provided rather 
than manually, but once you've learned that quirk of Python, what else do 
you need to know to solve this problem?

By the way, I know this is unsolicited advice, but I'm going to give it 
anyway. Look at your function:


def cmseditorlinemethod(self, ssn):
    c.details = Session.query(MSPResponse).filter(
                MSPResponse.beneficiaryssn == ssn).all()
    content = render('/cmseditorline.mako')
    return content


It looks to me like this function relies on no fewer than three global 
variables, two that you read from and one which you write to:

c
Session
MSPResponse

This is almost certainly poor design. Using global state is almost always 
harmful and should be avoided. 

(I don't include `render` in this, as using global functions is normally 
harmless.)

http://c2.com/cgi/wiki?GlobalVariablesAreBad



-- 
Steven

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Argument count mismatch RVince <rvince99@gmail.com> - 2011-04-21 12:33 -0700
  Re: Argument count mismatch Wolfgang Rohdewald <wolfgang@rohdewald.de> - 2011-04-21 21:43 +0200
  Re: Argument count mismatch Chris Angelico <rosuav@gmail.com> - 2011-04-22 06:15 +1000
  Re: Argument count mismatch John Gordon <gordon@panix.com> - 2011-04-21 20:33 +0000
  Re: Argument count mismatch Westley Martínez <anikom15@gmail.com> - 2011-04-21 15:41 -0700
  Re: Argument count mismatch Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-22 01:43 +0000
    Re: Argument count mismatch Daniel Kluev <dan.kluev@gmail.com> - 2011-04-22 21:19 +1100

csiph-web