import zlib, glob, os orig = new = 0 for dirname, dirs, files in os.walk('.'): for filename in glob.glob(dirname + '/*.pyc'): with open(filename, 'rb') as f: data = f.read() f_orig = len(data) f_new = len(zlib.compress(data)) print('%8d -> %8d %s' % (f_orig, f_new, filename)) orig += f_orig new += f_new print('%8d -> %8d %s' % (orig, new, 'Total'))