dirwalk.py generator version of os.path.walk

Greg Ewing greg at cosc.canterbury.ac.nz
Thu Feb 28 22:59:23 EST 2002


Jim Dennis wrote:
> 
>  I guess I'm just wary of recursion, particularly when I've read
>  that Python doesn't support tail-end recursion.

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!

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list