Confusion over calling a nested function inside a parent function

Duncan Booth duncan.booth at invalid.invalid
Fri Dec 22 08:39:56 EST 2006


Pyenos <pyenos at pyenos.org> wrote:

> [code]
> class WORK:
>     def getwork(self):
>         def choosetable(self):pass
>         choosetable() #TypeError: choosetable() takes exactly 1
>                       #argument (0 given)
> [/code]
> 
> 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.



More information about the Python-list mailing list