[Patches] [ python-Patches-652980 ] Generator form of os.path.walk

noreply@sourceforge.net noreply@sourceforge.net
Fri, 13 Dec 2002 21:46:03 -0800


Patches item #652980, was opened at 2002-12-12 17:29
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=652980&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Edward C. Jones (edcjones)
>Assigned to: Nobody/Anonymous (nobody)
Summary: Generator form of os.path.walk

Initial Comment:
 Generator yielding "top" and all files and directories
under it (except "." and ".."). "walk2" is much easier
to use than "walk" but lacks its flexibility. The
generator does a top-down traversal of the directory
tree. Unlike "walk", "walk2" raises an exception if top
does not exist. It is easy to modify the code to return
only files or only directories.


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-12-13 05:41

Message:
Logged In: YES 
user_id=21627

I would recommend to put this into the Cookbook for now. 
Actually, it's already there:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/
105873

and

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/
161542

I like the second snippet best, as it avoids building recursive 
generators.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/
52664

is similar: you can also iterate over the files, but it computes 
a list, instead of being a generator. I like that it allows to do 
globbing while it traverses.

For a Python patch, this is incomplete: It ought to patch all 
copies of the path module, and it ought to provide 
documentation (and perhaps test cases). Please use unified 
or context diffs.

As I said on python-dev, I'm -1 unless it also provides support 
for file types (i.e. it should return (filename, filetype) pairs, 
instead of returning file names).

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-12-12 18:58

Message:
Logged In: YES 
user_id=80475

The upload didn't make it.
Try resubmitting the patch.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=652980&group_id=5470