Why functional Python matters

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Apr 24 04:24:28 EDT 2003


"andrew cooke" <andrew at acooke.org> wrote in 
news:mailman.1051139802.16916.python-list at python.org:

> a related question - why does queue have to be passed to helper() in the
> code below?  i tried to define it inside walktree (but outside helper)
> since it's global to the function, but python objects saying that the
> local variable "queue" in helper is accessed before it's defined.  this
> seems to be an example of where closures would work perfectly...

Well, I don't know what you did but the problem was your's not Python's. I 
tried your code and it ran, I then added queue = [basepath] immediately 
before the def helper, and removed the parameter queue and the [basepath] 
from the call. I made no other changes. It still runs.

Perhaps you had some other version of the code where you tried assigning to 
queue inside the helper function? That would give the problem you describe, 
but simply mutating it as the code you posted does is fine.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list