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 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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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....
|
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...
|
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...
|
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...
| |
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(),...
|
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...
|
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...
|
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...
|
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,...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |