Recusive function inside a function can't find itself.

Terry Reedy tjreedy at udel.edu
Sat Oct 23 10:12:18 EDT 1999


In article <7ur95o$bk8$1 at news.wave.co.nz>, glyn at ninz.not.org.nz says...
>
>I've defined a function inside a function. I pass all
>the variables it needs into it through its argument
>list, which usually works. But what happens this time
>is that I get a "NameError: fill_code_list" where the
>function first calls itself recusively.
>
>Am I doing something wrong?
>(Other than pretending Python is Scheme?)

No.  The easiest thing to do is move the definition of fill_code_list() 
out of the body of display_codes() (perhaps with a leading underscore). 
 The only thing nesting a function definition does is to put the name 
binding into the function namespace (where the nested function cannot 
find it).  Or you can try to find a posting of mine from a couple of 
years ago on nested recursive functions.

Terry J. Reedy
 





More information about the Python-list mailing list