Musicreater/查看代码数.py

26 lines
761 B
Python
Raw Normal View History

2022-01-27 13:21:25 +00:00
# -*- conding: utf8 -*-
2022-01-28 10:29:51 +00:00
import os
2022-01-27 13:21:25 +00:00
from msctspt.funcOpera import keepart
2022-01-28 10:29:51 +00:00
m = 0
2022-01-27 13:21:25 +00:00
2022-01-28 10:29:51 +00:00
for path, dir_list, file_list in os.walk(r"./"):
for file_name in file_list:
if keepart(file_name, '.', None) == '.py':
2022-01-27 13:21:25 +00:00
file = os.path.join(path, file_name)
2022-01-28 10:29:51 +00:00
print("得到文件名:" + str(file))
for i in open(file, 'r', encoding="utf-8"):
code = i.replace(' ', '').replace('\n', '')
2022-01-27 13:21:25 +00:00
try:
code -= code[code.index('#'):]
except:
pass
if code:
2022-01-28 10:29:51 +00:00
print("\t" + code)
m += 1
2022-01-27 13:21:25 +00:00
else:
pass
2022-01-28 10:29:51 +00:00
input("\n最终代码行数为:" + str(m))