Why functional Python matters

andrew cooke andrew at acooke.org
Thu Apr 24 11:02:09 CEST 2003


so it does!  i have no idea how that happened, but thanks very much!

andrew

Duncan Booth said:

> "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?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
http://www.acooke.org/andrew





More information about the Python-list mailing list