I have the following code as part of a Python file, and it traverses .py files in the folder called controllers, and preforms some operations with them.
os.walk will return an iterable of 3-tuples for every directory and subdirectory in the specified top directory.
from os import walk
dirs = walk('/top/directory/here')
for path_from_top, subdirs, files in dirs:
for f in files:
if f.endswith('py'):
print str(path_from_top) + '/' + str(f)