# findpy.py
#
# Example of using os.walk and related functions.  This program finds the ten largest
# python files under a directory

topdir = "/Users/beazley"   #  Modify as appropriate

import os

size_and_filenames = []
for path, dirs, files in os.walk(topdir):
    for name in files:
        if name.endswith('.py'):
            fullname = os.path.join(path,name)
            if os.path.exists(fullname):
                size = os.path.getsize(fullname)
                size_and_filenames.append((size,fullname))

size_and_filenames.sort(reverse=True)
for size,name in size_and_filenames[:10]:
    print size, name
