统计python代码行数
#coding:utf-8import os
class StatLines(object):
def __init__(self,path):
self.path = path
def stat_lines(self):
file_list = os.listdir(self.path)
os.chdir(self.path)
total = 0
for file in file_list:
if file.endswith('.py'):
lines = open(file, encoding='utf-8').readlines()
count = 0
for line in lines:
if line == '\n':
continue
elif line.startswith('#'):
continue
else:
count += 1
total += count
print('%s has %d lines' %(file,count))
print('total lines is: %d' %total)
if __name__ == '__main__':
sl = StatLines('E:\\Python_Project\\addhost_v2\\addhosts')
sl.stat_lines()
页:
[1]