This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Generator form of os.path.walk
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: edcjones, gvanrossum, loewis, rhettinger
Priority: normal Keywords: patch

Created on 2002-12-12 22:29 by edcjones, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
posixpath.diff edcjones, 2002-12-13 00:50 diff for posixpath.py
Messages (4)
msg41996 - (view) Author: Edward C. Jones (edcjones) Date: 2002-12-12 22:29
 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.
msg41997 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-12-12 23:58
Logged In: YES 
user_id=80475

The upload didn't make it.
Try resubmitting the patch.
msg41998 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-12-13 10:41
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).
msg41999 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-04-24 17:54
Logged In: YES 
user_id=6380

Rejected this patch. Instead, we should use Tim's code and
call it os.walk().
History
Date User Action Args
2022-04-10 16:06:01adminsetgithub: 37609
2002-12-12 22:29:13edcjonescreate