The Python script used to count the total number of lines of code in the project, and the number of lines of python

Source: Internet
Author: User

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.

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.