[Python-Dev] os.path.walk() lacks 'depth first' option (original) (raw)
Tim Peters tim@zope.com
Tue, 13 May 2003 13:19:48 -0400
- Previous message: [Python-Dev] os.path.walk() lacks 'depth first' option
- Next message: [Python-Dev] Inplace multiply
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[Walter D=F6rwald]
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 :
files =3D os.walk('.').next()[-1]
- Previous message: [Python-Dev] os.path.walk() lacks 'depth first' option
- Next message: [Python-Dev] Inplace multiply
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]