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.
Import ospath= "/users/rony/workspace/ecommerce/ecommerce/hot-deploy/" Global totalcounttotalcount =0def 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)
Note: This recommendation only counts small files, and for very large files, performance can be slow
This article is from the "Records" blog, so be sure to keep this source http://wolfoxer.blog.51cto.com/53225/1575412
Python code that calculates the total row count of a program