On Thu, Nov 3, 2011 at 1:54 PM, Andrea Crotti <andrea.crott...@gmail.com> wrote: > All these ideas (shell and git hooks) are nice, but unfortunately > - it's svn not git > - it's windows not *nix > - we have to remove only the ones without the corresponding *py... > -- > http://mail.python.org/mailman/listinfo/python-list > Barely tested. Change the print functions to removes. Pass the top directory as the argument.
import os, sys for dirpath, dirnames, filenames in os.walk(sys.argv[1]): if dirpath.endswith("__pycache__"): thispath = dirpath[:-11] for f in filenames: if f.endswith(".pyc"): if not os.path.exists(os.path.join(thispath,f[:-1])): print("delete " + os.path.join(thispath,f)) else: for f in filenames: if f.endswith(".pyc"): if not os.path.exists(os.path.join(dirpath,f[:-1])): print("delete " + os.path.join(dirpath,f)) #os.remove(os.path.join(dirpath,f)) -- http://mail.python.org/mailman/listinfo/python-list