#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)