代码之家  ›  专栏  ›  技术社区  ›  Joe

计算Django项目中的代码行数

  •  9
  • Joe  · 技术社区  · 15 年前

    有没有一种简单的方法来计算您为Django项目编写的代码行?

    编辑:外壳材料很酷,但是在Windows上呢?

    5 回复  |  直到 8 年前
        1
  •  17
  •   Aiden Bell    15 年前

    是的:

    shell]$ find /my/source -name "*.py" -type f -exec cat {} + | wc -l
    

    这工作很不错。

        2
  •  7
  •   Steve Losh    15 年前

    你可能想看看 CLOC --它不特定于Django,但支持Python。它可以显示实际代码、注释、空行等的行计数。

        3
  •  4
  •   Xiong Chiamiov    7 年前

    从艾登的回答开始,在 a question of my own 最后,我遇到了这个可怕的混乱:

    # find the combined LOC of files
    # usage: loc Documents/fourU py html
    function loc {
        #find $1 -name $2 -type f -exec cat {} + | wc -l
        namelist=''
        let i=2
        while [ $i -le $# ]; do
            namelist="$namelist -name \"*.$@[$i]\""
            if [ $i != $# ]; then
                namelist="$namelist -or "
            fi
            let i=i+1
        done
        #echo $namelist
        #echo "find $1 $namelist" | sh
        #echo "find $1 $namelist" | sh | xargs cat
        echo "find $1 $namelist" | sh | xargs cat | wc -l
    }
    

    它允许您指定要匹配的任何数量的扩展名。据我所知,它输出了正确的答案,但是…我原以为这是一条单行线,否则我就不会从bash开始,它只是从那里发展起来的。

    我相信那些比我更了解的人可以在这方面有所改进,所以我将把它放到社区维基中。

        4
  •  1
  •   Dan Lorenc    15 年前

    查看unix上的wc命令。

        5
  •  0
  •   sharjeel    15 年前

    使用gnuwin32在Windows上获取wc命令( http://gnuwin32.sourceforge.net/packages/coreutils.htm )

    WC*Py