Skip to content

Commit 6e481ac

Browse files
committed
0007
1 parent 660d1ab commit 6e481ac

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Huangyunbo1996/0007/lines.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#-*- coding:utf-8 -*-
2+
import os
3+
4+
codeLines = 0
5+
commentLines = 0
6+
blankLines = 0
7+
8+
def CountLines(countDir,ext,ignore):
9+
10+
global codeLines
11+
global commentLines
12+
global blankLines
13+
14+
for file in os.listdir(countDir):
15+
if os.path.isdir(os.path.join(countDir,file)) and file != ignore:
16+
CountLines(os.path.join(countDir,file),ext,ignore)
17+
else:
18+
if os.path.splitext(file)[1].strip('.') == ext:
19+
print(file)
20+
with open(os.path.join(countDir,file),'r',encoding='utf-8') as f:
21+
for line in f:
22+
if line.strip().startswith('#'):
23+
commentLines = commentLines + 1
24+
elif line.strip() == '':
25+
blankLines = blankLines + 1
26+
else:
27+
codeLines = codeLines + 1
28+
29+
30+
31+
32+
if __name__ == '__main__':
33+
countDir = input('文件夹路径:')
34+
ext = input('文件类型:')
35+
ignore = input('需要忽略的文件夹:')
36+
37+
CountLines(countDir,ext,ignore)
38+
print('代码行数:%d,注释行数:%d,空行数:%d'%(codeLines,commentLines,blankLines))

0 commit comments

Comments
 (0)