Confusion over calling a nested function inside a parent function

P

Pyenos

Code:
class WORK:
    def getwork(self):
        def choosetable(self):pass
        choosetable() #TypeError: choosetable() takes exactly 1
                      #argument (0 given)

Calling choosetable() at the above location gives me the error
described above.
 
M

MacDonald

Pyenos said:
Code:
class WORK:
def getwork(self):
def choosetable(self):pass
choosetable() #TypeError: choosetable() takes exactly 1
#argument (0 given)

Calling choosetable() at the above location gives me the error
described above.

Although choosetable is a memeber of an instance method, it is not one
itself. It should not have self as it's first formal parameter.
 
D

Duncan Booth

Pyenos said:
Code:
class WORK:
def getwork(self):
def choosetable(self):pass
choosetable() #TypeError: choosetable() takes exactly 1
#argument (0 given)

Calling choosetable() at the above location gives me the error
described above.
A function defined inside a method is just a function, it's only when a
function is retrieved from the class dictionary (whether it was defined
there or assigned to the class later) that it becomes a method.

Just leave the self parameter off the choosetable function: you can still
access self from the outer scope of getwork.
 
P

Pyenos

MacDonald said:
Pyenos said:
Code:
class WORK:
def getwork(self):
def choosetable(self):pass
choosetable() #TypeError: choosetable() takes exactly 1
#argument (0 given)

Calling choosetable() at the above location gives me the error
described above.

Although choosetable is a memeber of an instance method, it is not one
itself. It should not have self as it's first formal parameter.

Code:
class WORK:
        def getwork(self):
                def choosetable():pass
                choosetable()

like this? thank you! ;-)
 
B

Bruno Desthuilliers

MacDonald a écrit :
Pyenos said:
Code:
class WORK:
def getwork(self):
def choosetable(self):pass
choosetable() #TypeError: choosetable() takes exactly 1
#argument (0 given)

Calling choosetable() at the above location gives me the error
described above.


Although choosetable is a memeber of an instance method,

s/is a member of/is defined in/
 
B

Bruno Desthuilliers

Pyenos a écrit :
Code:
[/QUOTE]

You already got the answer - just a pair of stylistic advices:
[QUOTE]
class WORK:[/QUOTE]

1/ By convention, ALL_UPPER names denote (pseudo) symbolic constants. 
The convention for class names is CamelCase.

2/ better to use new-style classes.

=>
class Work(object):
   ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top