Every day a Python applet 007 has a directory in which you have written your own program to count how many lines of code you have written. Include blank lines and comments, but be listed separately. __ Small Program

Source: Internet
Author: User
#coding =utf-8 "" "There is a directory, which is the program you wrote yourself, to count how many lines of code you have written.
Include blank lines and comments, but be listed separately. "" "Import sys,os,re def each (path): all=[] for root,dirs,files in Os.walk (path): #print" Root,dirs,files ", Root,dirs,files for name in Files:all.append (root+"/"+name) return all def deal (input): I F Os.path.splitext (input) [1] in [". Py", ". Pyw"]: total,comment,empty=0,0,0 f=open (input, "R") in_com Ment=false for line in F:total+=1 if Re.findall ("\" \ "\ $", line): If I
            N_comment:in_comment = False Else:in_comment = True
                If not Re.findall ("\s", line): Empty+=1 if line[0]== "#" or in_comment: Comment+=1 return total,comment,empty Else:return 0,0,0 if __name__ = = ' __main__ ': If Len (sys.argv) <=1:path = Os.path.split (Os.path.Realpath (__file__)) [0]+]/"print" The Script would calculate the LOC of the "file in" +path Else:print 
            "Calculating the file in" +sys.argv[1] if Os.path.isdir (sys.argv[1): path = sys.argv[1] Else: Print "Path error! Use this script as "+os.path.split" (Os.path.realpath (__file__)) [1]+ "[Path]" #print "-------------------------" #pr
        int each (path) a,c,e=0,0,0 to I in each (path): Ta,tc,te=deal (i) A+=ta C+=TC
    
    
    
    
    
    
     E+=te print "Total lines:%s. Empty lines:%s. Comment lines:%s."% (A, E, c)

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.