1 ImportOS2 ImportEasygui as G3 4 defStatisticecodeline (dir_name):5File_dict = {". PY": [0,0],". C": [0,0],". cpp": [0,0],". Pas": [0,0],". ASM": [0,0]}6All_child_dir =Os.walk (dir_name)7 8 forIteminchAll_child_dir:9 forFileinchItem[2]:TenFile_name,file_extension =os.path.splitext (file) One ifFile_extensioninchfile_dict: AFile_dict[file_extension][0] + = 1 - - #------------------------------------------------------------ theWith open (Os.path.join (item[0],file),"R", encoding='Utf-8') as F: - forIinchF: -FILE_DICT[FILE_EXTENSION][1] + = 1 - #------------------------------------------------------------ + - Else: + Pass A at returnfile_dict - - -Dir_name = G.diropenbox ()#here is actually a directory to get the recursive, in the directory to find -File_dict =statisticecodeline (dir_name) -Total_line_count =0 inDetail ="" - forKey,valueinchFile_dict.items (): toTotal_line_count + = Value[1] +Detail + = str (key) +"source File"+ str (value[0]) +"One, source code"+ str (value[1]) +"line \ n" - theTotal_line_count ="you have now accumulated {0} Lines of code, the completion of the degree {1}%\n 100,000 lines of code is not the {2} line, please continue to work! ". Format (total_line_count,total_line_count/1000,100000-total_line_count) * $G.textbox (Total_line_count,"Statistical Results", Text=detail)#you can use print instead if you want.
Python Basic Combat--Statistics Code Amount