我是一名新学员。这是我写的课程。但似乎有很多问题。我想要计算总行数,空行数,注释行数和代码行数。但我不能运行这个程序。我知道我认为评论行的方式是错误的。真的需要一些帮助。
def FileLineCount(filename):
(shotname,extension) = os.path.splitext(filename);
if extension == '.java' : # file type
file = open(filename,'r');
allLines = file.readlines();
file.close();
lineCount =0;
commentCount = 0;
blankCount = 0;
codeCount = 0;
for eachLine in allLines:
if eachLine.find('//'): #LINECOMMENT
commentCount += 1;
else :
if eachLine == "":
blankCount += 1;
else :
codeCount += 1;
lineCount = lineCount + 1;
self.all += lineCount;
self.allComment += commentCount;
self.allBlank += blankCount;
self.allSource += codeCount;
print filename;
print ' Total :',lineCount ;
print ' Comment :',commentCount;
print ' Blank :',blankCount;
print ' Source :',codeCount;