Re: [Python-Dev] os.path.walk() lacks 'depth first' option

Guido van Rossum wrote:
I like the increased flexibility. But how about the following version?
I don't think there's any need for such increased flexibility. Let's stop while we're ahead. Fixing the silent errors case is important (see various posts here). Your generalization is a YAGNI though.
True, getting a list of files in the current directory even works with the current os.walk: sum([[os.path.join(x[0], f) for f in x[2]] for x in os.walk(".")], []) Bye, Walter Dörwald

[Walter Dörwald]
True, getting a list of files in the current directory even works with the current os.walk:
sum([[os.path.join(x[0], f) for f in x[2]] for x in os.walk(".")], [])
Convoluted one-liners are poor Python style, IMO. That walks the entire tree, too. If you want the files in just the current directory, for root, dirs, files in os.walk('.'): break print files or if clarity is disturbing <wink>: files = os.walk('.').next()[-1]
participants (2)
-
Tim Peters
-
Walter Dörwald