Skip to content

Commit a714626

Browse files
committed
count
1 parent 4b91054 commit a714626

File tree

4 files changed

+43
-64
lines changed

4 files changed

+43
-64
lines changed
File renamed without changes.

count_module/count.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
from collections import Counter
3+
4+
modules = set()
5+
all_modules = {}
6+
for root, dirs, files in os.walk("..", topdown=False):
7+
# print('========', root,dirs
8+
for name in files:
9+
# print('--', name)
10+
if name.endswith('.py'):
11+
with open(root + os.path.sep + name) as f:
12+
for line in f:
13+
line = line.lstrip()
14+
if line.startswith('from') or line.startswith('import'):
15+
# print('--------',line)
16+
module = line.split()[1]
17+
module = module.split('.')[0]
18+
if module:
19+
# print(module)
20+
modules.add(module)
21+
if root.count(os.path.sep) <= 1:
22+
# print(modules)
23+
for m in modules:
24+
all_modules[m] = all_modules.get(m, 0) + 1
25+
modules = set()
26+
# print(all_modules)
27+
c = Counter(all_modules).most_common()
28+
for i in c:
29+
if i[1] > 1:
30+
print(i)

count_module/readme.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## 引入模块统计
2+
3+
对于编程教室案例代码中使用到的模块进行统计。
4+
5+
参考阅读:
6+
7+
8+
9+
更多实用有趣的例程
10+
11+
欢迎关注“**Crossin的编程教室**”及同名 [知乎专栏](https://zhuanlan.zhihu.com/crossin)
12+
13+
![crossincode](../crossin-logo.png)

train.py

-64
This file was deleted.

0 commit comments

Comments
 (0)