Re: [Tutor] Passing Functions or Code as Parameters

2005-10-28 Thread Kent Johnson
Ed Singleton wrote: > On 27/10/05, Kent Johnson <[EMAIL PROTECTED]> wrote: > >>Ed Singleton wrote: >>>Can I pass a block of code that will be executed within the function's >>>scope? >> >>Yes, you can define a function within traverse() and pass that function to >>things_to_do(), but I don't know

Re: [Tutor] Passing Functions or Code as Parameters

2005-10-27 Thread Kent Johnson
Ed Singleton wrote: > Wow, thanks again, Kent. > > If my understanding of functions in Python is correct, then the > do_something() function won't have access to the variables inside > traverse. Is this right? Yes, that's right. Python is lexically scoped which means you have access to variable

Re: [Tutor] Passing Functions or Code as Parameters

2005-10-27 Thread Kent Johnson
Ed Singleton wrote: > How can I pass a block of code to a function for it to perform within itself? > > For example, I wrote a small function that recurses through a > directory structure but keeps a track of the depth: > > What I want to do is something like: > > from path import path > > def

[Tutor] Passing Functions or Code as Parameters

2005-10-27 Thread Ed Singleton
How can I pass a block of code to a function for it to perform within itself? For example, I wrote a small function that recurses through a directory structure but keeps a track of the depth: from path import path def traverse(directory, depth=0): thedir = path(directory) for item in the