1 | n/a | # Remove all the .pyc and .pyo files under ../Lib. |
---|
2 | n/a | |
---|
3 | n/a | |
---|
4 | n/a | def deltree(root): |
---|
5 | n/a | import os |
---|
6 | n/a | from os.path import join |
---|
7 | n/a | |
---|
8 | n/a | npyc = npyo = 0 |
---|
9 | n/a | for root, dirs, files in os.walk(root): |
---|
10 | n/a | for name in files: |
---|
11 | n/a | delete = False |
---|
12 | n/a | if name.endswith('.pyc'): |
---|
13 | n/a | delete = True |
---|
14 | n/a | npyc += 1 |
---|
15 | n/a | elif name.endswith('.pyo'): |
---|
16 | n/a | delete = True |
---|
17 | n/a | npyo += 1 |
---|
18 | n/a | |
---|
19 | n/a | if delete: |
---|
20 | n/a | os.remove(join(root, name)) |
---|
21 | n/a | |
---|
22 | n/a | return npyc, npyo |
---|
23 | n/a | |
---|
24 | n/a | npyc, npyo = deltree("../Lib") |
---|
25 | n/a | print(npyc, ".pyc deleted,", npyo, ".pyo deleted") |
---|