Source

# Remove all the .pyc and .pyo files under ../Lib.importsysdefdeltree(root):importosfromos.pathimportjoinnpyc=npyo=0forroot,dirs,filesinos.walk(root):fornameinfiles:delete=Falseifname.endswith('.pyc'):delete=Truenpyc+=1elifname.endswith('.pyo'):delete=Truenpyo+=1ifdelete:os.remove(join(root,name))returnnpyc,npyopath="../Lib"iflen(sys.argv)>1:path=sys.argv[1]npyc,npyo=deltree(path)printnpyc,".pyc deleted,",npyo,".pyo deleted"