python 行数的代码,python行数代码,#! /usr/bin/
文章由Byrx.net分享于2019-03-23 09:03:15
python 行数的代码,python行数代码,#! /usr/bin/
#! /usr/bin/env pythonimport reclass module(object): def __init__(self,name): self.n=name self.pattern=re.compile(".*#[^!].*",re.I) self.pattern1=re.compile("^\\s\\s*$\\s") def run(self): n=0;zhushi=0;space=0 zhushi=0;space=0 zhushi_=[];space_=[] fi=open(self.n,"r") for i in fi: n+=1 if self.pattern.match(i): zhushi+=1 zhushi_.append(n) elif self.pattern1.match(i): space+=1 space_.append(n) print "the zhushi is %d zhe space is %d,--the total is %d" %(zhushi,space,n) print "the zhushi in %s,zhe space in %s" %(zhushi_,space_) fi.close()if __name__=="__main__": try: #name=raw_input("please input the file name-->") name="1.py" m=module(name) m.run() except Exception as err: print err#该片段来自于http://byrx.net
评论关闭