The Python script used to count the total number of lines of code in the project, and the number of lines of python
Recently, I need to calculate the total number of lines of code in the project and write a Python applet. I have to say how concise Python is. If I use Java to write it, at least twice the current code.
[Code]
Import OS
Path = "/Users/rony/workspace/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)
The code analysis is here. The example is relatively simple.