forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.py
More file actions
39 lines (32 loc) · 945 Bytes
/
Test.py
File metadata and controls
39 lines (32 loc) · 945 Bytes
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
__author__ = 'Tracy'
import os, io, re
commentLines = 0
whiteLines = 0
comment = False
path = 'F:\AllKindsOfWorkplace\PyCharmWorkplace\PythonLearning'
count = 0
def tree(path):
filelist = os.listdir(path)
for file in filelist:
if os.path.isdir(os.path.join(path, file)):
tree(os.path.join(path, file))
else:
filename = os.path.basename(os.path.join(path, file))
if filename.endswith(".py"):
# print(filename)
file = io.open(os.path.join(path, file))
parse(file)
file.close()
def parse(file):
global commentLines
global whiteLines
global comment
for line in file.readlines():
# line = line.strip("\n")
if line.startswith("#"):
commentLines += 1
elif re.match("^[\\s&&[^\\n]]*$", line):
whiteLines += 1
tree(path)
print(commentLines)
print(whiteLines)