Staging
v0.5.1
https://github.com/python/cpython
Revision 59ade080796be93cbe31f3c0c339f8e5756e9a1d authored by Ka-Ping Yee on 01 March 2001, 03:55:35 UTC, committed by Ka-Ping Yee on 01 March 2001, 03:55:35 UTC
1 parent abb379e
Raw File
Tip revision: 59ade080796be93cbe31f3c0c339f8e5756e9a1d authored by Ka-Ping Yee on 01 March 2001, 03:55:35 UTC
Add getlineno() routine to account for LINENO optimization.
Tip revision: 59ade08
rmpyc.py
# Remove all the .pyc and .pyo files under ../Lib.

from __future__ import nested_scopes

def deltree(root):
    import os
    def rm(path):
        os.unlink(path)
    npyc = npyo = 0
    dirs = [root]
    while dirs:
        dir = dirs.pop()
        for short in os.listdir(dir):
            full = os.path.join(dir, short)
            if os.path.isdir(full):
                dirs.append(full)
            elif short.endswith(".pyc"):
                npyc += 1
                rm(full)
            elif short.endswith(".pyo"):
                npyo += 1
                rm(full)
    return npyc, npyo

npyc, npyo = deltree("../Lib")
print npyc, ".pyc deleted,", npyo, ".pyo deleted"
back to top