zoukankan      html  css  js  c++  java
  • python学习之——计算给出代码中注释、代码、空行的行数

    题目:计算给出代码中注释、代码、空行的行数

    来源:网络

    思路:注释行以 ‘#’开头,空行以 ‘ ’ 开头,以此作为判断

    def count_linenum(fname):
        fobj = open(fname,"rU")
        #print fobj.readlines()
        count_blankline = 0
        count_notes = 0
        count_code = 0
        for eachLine in fobj:
            if eachLine[0] == '
    ':
                count_blankline += 1
            elif eachLine[0] == '#':
                count_notes += 1
            else:
                count_code += 1
        print "count_blankline:%d" %count_blankline
        print "count_notes:%d" %count_notes
        print "count_code:%d" %count_notes
    
        fobj.close()
    
    if __name__ == '__main__':
        filename = raw_input("please enter filename:")
        count_linenum(filename)
        
  • 相关阅读:
    freeswitch录音功能
    jdk安装
    maven阿里云镜像
    idea安装
    idea新建maven项目
    tomcat安装
    idea新建maven web项目
    idea新建java项目
    webpack使用
    ACE 安装指南及示例
  • 原文地址:https://www.cnblogs.com/cloverclt/p/4911839.html
Copyright © 2011-2022 走看看