Python script sharing for counting the total number of lines of code in a project

Source: Internet
Author: User
Tags python script

This article mainly introduces the statistical project in the total number of code in the Python script sharing, this article directly gives the implementation code, the need for friends can refer to the following

Recently you need to count the total number of lines of code in your project, write a Python applet, and have to say how concise Python is, if you write it in Java at least twice times the code.

[Code]

Import OS

Path= "/users/rony/workspace/ecommerce/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 analysis on the code here, the example is relatively simple.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.