G
gregpinero
In the example from help(os.walk) it lists this:
from os.path import join, getsize
for root, dirs, files in walk('python/Lib/email'):
print root, "consumes",
print sum([getsize(join(root, name)) for name in files]),
print "bytes in", len(files), "non-directory files"
if 'CVS' in dirs:
dirs.remove('CVS') # don't visit CVS directories
What I'm wondering is how does the "dirs.remove('CVS')" line prevent
os.walk from visiting that directory? how does the walk function know
what you do to the dirs variable? I tried looking at the code in
os.py but it wasn't clear to me there either.
Thanks,
Greg
from os.path import join, getsize
for root, dirs, files in walk('python/Lib/email'):
print root, "consumes",
print sum([getsize(join(root, name)) for name in files]),
print "bytes in", len(files), "non-directory files"
if 'CVS' in dirs:
dirs.remove('CVS') # don't visit CVS directories
What I'm wondering is how does the "dirs.remove('CVS')" line prevent
os.walk from visiting that directory? how does the walk function know
what you do to the dirs variable? I tried looking at the code in
os.py but it wasn't clear to me there either.
Thanks,
Greg