计算Django项目中的代码行

时间:2009-07-15 19:17:16

标签: python django

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

编辑:shell的东西很酷,但在Windows上怎么样?

5 个答案:

答案 0 :(得分:18)

是的:

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

工作很好'联合国

答案 1 :(得分:7)

您可能希望查看CLOC - 它不是特定于Django但它支持Python。它可以显示实际代码,注释,空行等的行数。

答案 2 :(得分:4)

从艾登的答案开始,并在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中开始,它只是从那里开始增长。

我确信那些比我更了解的人可以改进这一点,所以我将把它放在社区维基中。

答案 3 :(得分:1)

在unix上查看wc命令。

答案 4 :(得分:0)

使用GnuWin32(http://gnuwin32.sourceforge.net/packages/coreutils.htm

在Windows上获取wc命令
  

wc * .py