-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path查看文件夹内代码行数.py
51 lines (43 loc) · 1.26 KB
/
查看文件夹内代码行数.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
code_lines = list()
notation_lines = list()
blank_lines = list()
def process_file(filename):
global code_lines
global notation_lines
global blank_lines
with open(filename, 'r') as file:
for line in file.readlines():
_line = line.strip()
if not _line:
blank_lines.append(_line)
elif _line.startswith('#'):
notation_lines.append(_line)
else:
code_lines.append(_line)
def show_result():
global code_lines
global notation_lines
global blank_lines
print('-'*20)
print('code:', len(code_lines))
for line in code_lines:
print(line)
print('-' * 20)
print('notation:', len(notation_lines))
for line in notation_lines:
print(line)
print('-' * 20)
print('blank:', len(blank_lines))
code_lines.clear()
notation_lines.clear()
blank_lines.clear()
def process_files(path='../modiz'):
files = os.listdir(path)
for file in files:
if file.endswith('.py'):
print('='*30)
print('current file:', os.path.join(path, file))
process_file(os.path.join(path, file))
show_result()
process_files()