473,503 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Error when trying to pass list into function.

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?

Thanks!
Erik

Apr 2 '07 #1
3 5250
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
Apr 2 '07 #2
On Apr 2, 1:43 pm, "erikcw" <erikwickst...@gmail.comwrote:
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?

Thanks!
Erik
You need to do this:

def calculate(self, dta):
# stub
Because when you call a method in a class with this:
self.calculate(crea), you pass in an instance of the object (self) AND
the list.

Mike

Apr 2 '07 #3
erikcw schrieb:
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?

Thanks!
Erik
The first argument to a method (a function bound to an instance) is
always the instance itself. (I assume you *have* a method here because
you call self.calculate(crea), what will itself call
SomeClass.calculate(self, crea).)

For further information, consult the python tutorial
http://docs.python.org/tut/node11.ht...00000000000000.

HTH,
Stargaming
Apr 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1897
by: Sean Abrahams | last post by:
The following is a reprint of a message I sent to the tutor list a long time ago, that I haven't gotten around to discussing with anyone else and failed to hear a reply on the tutor list. Hoping...
4
1718
by: John | last post by:
Hi all; I write my first code using vector and list. When I run it, segmentation fault. Try to debug it, but it can not pass linking with -g option. What is the error with it? Thanks a lot....
2
9776
by: Chuck Martin | last post by:
I am having a most frustrating problem that references, web searches, and other resources are no help so far in solving. Basically, I'm trying to design a pop-up window to be called with a funciton...
8
1814
by: grundmann | last post by:
Hello, i got a strange compiler error. When compiling the following: // forward declarations typedef AvlTree<LineSegment,LineSegmentComperator> LSTree; void handleEventPoint (const...
18
4705
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
7
6954
by: yinglcs | last post by:
Hi, I have a function which calls stl sort(). I pass in a STL list of 'Rect' (my own class), like this: void sortListY(const list<Rect>& rectList) { sort(rectList.begin(),...
22
3219
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
5
8797
by: Rahul B | last post by:
Hi, I have very little knowledge about creating Procedures/functions in DB2. When i tried to create the test function like CREATE FUNCTION GET_TEST (P_TEST_ID INTEGER, P_SEL_OR_SORT...
3
2506
by: Ray D. | last post by:
Hey all, I'm trying to pass a list into a function to edit it but when I compile using g++ I continue to get the following error: maintainNeighbors.cpp:104: error: invalid initialization of...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.