dirwalk.py generator version of os.path.walk
Tim Peters
tim.one at comcast.net
Fri Mar 1 00:12:45 EST 2002
[Jim Dennis]
> I guess I'm just wary of recursion, particularly when I've read
> that Python doesn't support tail-end recursion.
[Greg Ewing]
> That's only an issue if you abuse recursion for the likes of
> iterating along a linear list. In languages which optimise
> tail-recursion, it is common for people to do things like
> that using recursion, but it would be silly in Python.
> If, e.g. the list were a million items long, you'd need a
> million stack frames.
>
> But here, the stack is only going to be as deep as the
> directory hierarchy, which is hardly going to kill you.
>
> So, don't just blindly reject recursion -- think about
> how it applies to the problem at hand!
If I were Jim, I'd continue leaving recursion out of this specific
application. An explicit "todo list" trivially supports either
breadth-first or depth-first traversal (a choice Jim explicitly mentioned as
something he wants to control). Calling it "a stack" is an illusion
suffered by those blindly embracing recursion <wink>.
More information about the Python-list
mailing list