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

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.