Python code for calculating the total number of lines of a program, and number of lines of python code
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.
Import ospath = "/Users/rony/workspace/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 + countf; print (child) print (countf) cfile (path) print (totalcount)
The code analysis is here. The example is relatively simple. If you need to download the code, go to this