Python code example that calculates the number of lines of code

Source: Internet
Author: User
Tags webhost
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.