This article mainly introduces the Python statistics code line number Simple example of the relevant data, the need for friends can refer to the following
Python Statistics code line number Simple instance
When you send a test, you find that you need to count lines of code
Then wrote a small program to count the number of lines of their own code.
#calclate_code_lines. py Import os def afileline (f_path): res = 0 F = open (F_path) for lines in F:if lines.spli T (): Res + = 1 return res if name== ' main ': host = ' E: ' +os.sep+ ' develop ' +os.sep+ ' dev_workspace ' +os.sep+ ' Aptanastu Dio3 ' +os.sep+ ' webhost ' allfiles = 0 allline = 0 for root,dirs,files in Os.walk (host): For afile in Files : if (Root.startswith (host+os.sep+ ' entries ')): Continue Elif (Root.startswith (host+os.sep+ '. SVN ') ): Continue Elif (Root.startswith (host+os.sep+ '. Settings ')): Continue Elif (Root.startswith (host +os.sep+ ' logs '): Continue Elif (Root.startswith (host+os.sep+ ' static)): Continue Elif (root.st Artswith (host+os.sep+ ' payload ' +os.sep+ '. SVN '): Continue elif (root.startswith ' host+os.sep+ ' dist '. SV n ')): Continue Elif (Root.startswith (host+os.sep+ ' Dsync ' +os.sep+ '. SVN ')): Continue Elif (root.st Artswith (host+os.sep+ ' HCAche ' +os.sep+ '. SVN '): Continue Elif (Root.startswith (host+os.sep+ ' test ' +os.sep+ '. SVN ')): Continue Elif (Root.startswith (host+os.sep+ ' webhost ' +os.sep+ '. SVN ')): Continue Elif (Root.startswith (host+os.sep+ ' W SGI ' +os.sep+ '. SVN '): Continue Elif (Root.startswith (host+os.sep+ ' hcache ' +os.sep+ ' templates ' +os.sep+ '. SVN ')): Continue Elif (Root.startswith (host+os.sep+ ' dsync ' +os.sep+ ' hcache ' +os.sep+ '. SVN ')): Continue E Lse:ext = Afile.split ('. ') ext = ext[-1] if (ext in [' py ', ' css ', ' JS ', ' html ', ' txt ', ' docx ', ' Wsgi ')): Itpath = Root+os.sep+afile Allfiles + = 1 allline +=afileline (itpath) print (root+os.sep+afile) print (' Total: ' , allfiles) print (' Total lines: ', allline)
This can then be modified to facilitate future code statistics
"Recommended"
1. Special recommendation : "PHP Programmer Toolkit" V0.1 version download
2. Python Free video tutorial
3. Python Object-oriented video tutorial