這篇文章主要介紹了python 統計程式碼行數簡單實例的相關資料,需要的朋友可以參考下
python 統計程式碼行數簡單實例
#送測的時候,發現需要統計程式碼行數
於是寫了個小程式統計自己的程式碼的行數。
#calclate_code_lines.py import os def afileline(f_path): res = 0 f = open(f_path) for lines in f: if lines.split(): res += 1 return res if name=='main': host = 'E:'+os.sep+'develop'+os.sep+'dev_workspace'+os.sep+'AptanaStudio3'+os.sep+'webhost' allfiles = 0 allline = 0 for root,dirs,files in os.walk(host): for afile in files: if(root.startswith(host+os.sep+'entries')): continue elif(root.startswith(host+os.sep+'.svn')): continue elif(root.startswith(host+os.sep+'.settings')): continue elif(root.startswith(host+os.sep+'logs')): continue elif(root.startswith(host+os.sep+'static')): continue elif(root.startswith(host+os.sep+'payload'+os.sep+'.svn')): continue elif(root.startswith(host+os.sep+'dist'+os.sep+'.svn')): continue elif(root.startswith(host+os.sep+'dsync'+os.sep+'.svn')): continue elif(root.startswith(host+os.sep+'hcache'+os.sep+'.svn')): continue elif(root.startswith(host+os.sep+'test'+os.sep+'.svn')): continue elif(root.startswith(host+os.sep+'webhost'+os.sep+'.svn')): continue elif(root.startswith(host+os.sep+'wsgi'+os.sep+'.svn')): continue elif(root.startswith(host+os.sep+'hcache'+os.sep+'templates'+os.sep+'.svn')): continue elif(root.startswith(host+os.sep+'dsync'+os.sep+'hcache'+os.sep+'.svn')): continue else: ext = afile.split('.') ext = ext[-1] if (ext in ['py','css','js','html','txt','docx','wsgi']): itpath = root+os.sep+afile allfiles += 1 allline +=afileline(itpath) print (root+os.sep+afile) print ('Total: ',allfiles) print ('Total lines:',allline)
之後可以將此改造下便於以後的程式碼統計
【相關推薦】
1. 特別推薦:「php程式設計師工具箱」V0.1版本下載
#2. Python免費影片教學
以上是計算程式碼行數的python程式碼範例的詳細內容。更多資訊請關注PHP中文網其他相關文章!