You don't need it. I ran the following 2 scripts:
#test1.py
import os
source_dir = '.'
ext = '.txt'
for dirName, subdirList, fileList in os.walk(source_dir):
if not any(os.path.splitext(fileName)[1].lower() == ext for fileName in fileList):
print ' skipping "{}"'.format(dirName)
continue
else: # why is this clause needed to continue this iteration of a loop?
print 'contains "{}"'.format(dirName)
pass
print 'processing "{}" which has "{}" files'.format(dirName, ext)
and
#test2.py
import os
source_dir = '.'
ext = '.txt'
for dirName, subdirList, fileList in os.walk(source_dir):
if not any(os.path.splitext(fileName)[1].lower() == ext for fileName in fileList):
print ' skipping "{}"'.format(dirName)
continue
#else: # why is this clause needed to continue this iteration of a loop?
# print 'contains "{}"'.format(dirName)
# pass
print 'processing "{}" which has "{}" files'.format(dirName, ext)
I ran them as:
python test1.py > junk.log
python test2.py > junk.log2
Here's the first couple lines of junk.log
:
test $ head junk.log
processing "." which has ".txt" files
skipping "./new"
skipping "./unum"
processing "./unum/kiv-unum-409befe069ac" which has ".txt" files
skipping "./unum/kiv-unum-409befe069ac/build"
skipping "./unum/kiv-unum-409befe069ac/build/bdist.macosx-10.3-fat"
skipping "./unum/kiv-unum-409befe069ac/build/lib"
skipping "./unum/kiv-unum-409befe069ac/build/lib/tests"
skipping "./unum/kiv-unum-409befe069ac/build/lib/unum"
skipping "./unum/kiv-unum-409befe069ac/build/lib/unum/units
Notice the presence of "processing" lines.
Then I diff
the output:
diff junk.log junk.log2
with the following results:
0a1
> contains "."
3a5
> contains "./unum/kiv-unum-409befe069ac"
14a17
> contains "./unum/kiv-unum-409befe069ac/docs"
16a20
> contains "./unum/kiv-unum-409befe069ac/nose-1.2.1-py2.7.egg/EGG-INFO"
19a24
> contains "./unum/kiv-unum-409befe069ac/nose-1.2.1-py2.7.egg/nose"
30a36
> contains "./unum/kiv-unum-409befe069ac/Unum.egg-info"
Note that there are no differences on the "processing" lines.