最近須要統計一下項目中代碼的總行數,寫了一個Python小程序,不得不說Python是多麼的簡潔,若是用Java寫至少是如今代碼的2倍。css
import os path="/Users/rony/workspace/ecommerce/ecommerce/hot-deploy/" global totalcount totalcount =0 def cfile (path): allfiles = os.listdir(path) for file in allfiles: child = os.path.join(path,file) if os.path.isdir(child): cfile(child) else: filename,fileext= os.path.splitext(child) print(fileext) #file type need to calculate if fileext in ['.java', '.jsp', '.html', '.htm', '.xml', '.sql', '.js', '.ftl', '.css','.groovy'] : countf = len(open(child,'rU').readlines()) global totalcount totalcount=totalcount+countf; print(child) print(countf) cfile(path) print(totalcount)
關於代碼上的分析就到這裏,例子比較簡單,若是須要下載代碼請移步這html