1 #-*- coding:utf-8 -*- 2 ''' 3 Created on 2018年8月15日 4 5 @author: anyd 6 ''' 7 import os 8 list_line = [] 9 filepath = str(raw_input("Please input the code path:")) 10 for i,j,k in os.walk(filepath): 11 for file in k: 12 with open(filepath + file,'r') as f: 13 total_line = len(f.readlines()) 14 # print "该文件的总行数为:",total_line 15 with open(filepath + file,'r') as f: 16 empty_line = f.readlines().count(" ") 17 # print "该文件的总空行数为:",empty_line 18 real_line = total_line - empty_line 19 list_line.append(real_line) 20 21 sum_line = sum(list_line) 22 print "CCT result is:",sum_line
输出:
请输入需要读取文件的路径:D:code
796