Recently you need to count the total number of lines of code in the project, write a Python applet, and have to say how concise Python is, if it's written in Java at least twice times the current code.
ImportOspath="/users/rony/workspace/ecommerce/ecommerce/hot-deploy/"GlobalTotalcounttotalcount=0defCFile (path): Allfiles=os.listdir (path) forFileinchAllfiles:child=Os.path.join (path,file)ifOs.path.isdir (Child): CFile (Child)Else: Filename,fileext=Os.path.splitext (Child)Print(Fileext)#file type need to calculate ifFileextinch['. Java','. JSP','. html','. htm','. XML','. SQL','. js','. FTL','. CSS','. Groovy']: countf= Len (open (Child,'RU'). ReadLines ())GlobalTotalCount TotalCount=totalcount+countf; Print(Child)Print(countf) CFile (path)Print(TotalCount)
The analysis on the code here, the example is relatively simple, if you need to download the code, please visit this
Python code that calculates the total row count of a program