Error when trying to pass list into function.

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon Apr 2 21:28:20 CEST 2007


erikcw a écrit :
> Hi,
> 
> I'm getting the following error when I try to pass a list into a
> function.
> 
> My List: crea =[(u'218124172', u'536', u'32394'), (u'218320282',
> u'1323', u'77931')]
> 
> Traceback (most recent call last):
>   File "wa.py", line 118, in ?
>     curHandler.walkData()
>   File "wa.py", line 49, in walkData
>     self.results[parent][child]['results'] = self.calculate(crea)
> #pass in list of tuples
> TypeError: calculate() takes exactly 1 argument (2 given)
> 
> def calculate(dta):
> #stub
> 
> How can I make this work?

In Python, the first argument of an instance method is the instance on 
which it has to operate [1]. IOW, your problem is with the definition of 
calculate(). You want:

class DontKnowWhat(object):
   def calculate(self, data):
     # code here

[1] you don't have to pass this argument - this will be handled by 
Python - but you need to declare it.

HTH



More information about the Python-list mailing list