A simple generator application

Doug Fort doug.fort at verizon.net
Sun Oct 13 12:42:09 EDT 2002


On Sun, 13 Oct 2002 09:46:28 +0000, Oren Tirosh wrote:

> On Sat, Oct 12, 2002 at 05:22:40PM +0000, Doug Fort wrote:
>> def dirWalker(top):
>>     """
>>     a generator that walks a directory tree
>> 
>>     This code is based on os.path.walk, with the callback function
>>     replaced by a yield and recursion replaced by crude iteration
>>     """
>>     dirstack = [top]
>>     while len(dirstack) > 0:
> ...
> 
> Why remove the recursion? It's the easiest way to write this code. I find
> it much more straightforward than maintaining an explicit stack.
> 
I couldn't get the generator to work with recursion. I'd be grateful for
an example.

-- 
Doug Fort, Programmer
http:/www.dougfort.net




More information about the Python-list mailing list