Python 基礎實戰 -- 統計代碼量

來源:互聯網
上載者:User

標籤:UI   statistic   post   ota   python 基礎   ict   key   pen   detail   

 1 import os 2 import easygui as g 3  4 def StatisticeCodeLine(dir_name): 5     file_dict = {".py":[0,0],".c":[0,0],".cpp":[0,0],".pas":[0,0],".asm":[0,0]} 6     all_child_dir = os.walk(dir_name) 7      8     for item in all_child_dir: 9         for file in item[2]:10             file_name,file_extension = os.path.splitext(file)11             if file_extension in file_dict:12                 file_dict[file_extension][0] += 113 14             #------------------------------------------------------------15                 with open(os.path.join(item[0],file),"r",encoding=‘utf-8‘) as f:16                     for i in f:17                         file_dict[file_extension][1] += 118             #------------------------------------------------------------19                 20             else:21                 pass22        23     return file_dict24 25 26 dir_name = g.diropenbox() #這裡其實是一個擷取需要遞迴的目錄,在目錄裡找27 file_dict = StatisticeCodeLine(dir_name)28 total_line_count = 029 detail = ""30 for key,value in file_dict.items():31     total_line_count += value[1]32     detail += str(key) + "源檔案" + str(value[0]) + "個,原始碼" + str(value[1])+"行\n"33 34 total_line_count = "您目前累積編寫了{0}行代碼,完成度{1}%\n離10萬行代碼還差{2}行,請繼續努力!".format(total_line_count,total_line_count / 1000,100000-total_line_count)35 36 g.textbox(total_line_count,"統計結果",text=detail) #其實你想的話這裡也可以用print替代

 

Python 基礎實戰 -- 統計代碼量

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.