1# Remove all the .pyc files under ../Lib. 2 3 4def deltree(root): 5 import os 6 from os.path import join 7 8 npyc = 0 9 for root, dirs, files in os.walk(root): 10 for name in files: 11 # to be thorough 12 if name.endswith(('.pyc', '.pyo')): 13 npyc += 1 14 os.remove(join(root, name)) 15 16 return npyc 17 18npyc = deltree("../Lib") 19print(npyc, ".pyc deleted") 20