【问题标题】:counting source code lines in python project计算python项目中的源代码行
【发布时间】:2011-11-27 07:41:26
【问题描述】:

如何计算python项目中包含多个子目录的项目中写入的行数。例如 dir 结构就像

A  
 \ <*some files here*>\  
  B  
   \ <*some files here*>\ ... and so on...

【问题讨论】:

标签: python version-control code-metrics


【解决方案1】:

您可以在 linux 中使用 find 实用程序。

在命令提示符下:

$ find <project_directory_path> -name '*.py' | xargs wc -l

这将为您提供 project_directory 中所有以 .py 结尾的文件的计数,最后是总数。 (我假设您只想要 .py 文件的数量)

如果你只想要总数而不想要别的,你可以使用:

$ find <project_directory_path> -name '*.py' | xargs wc -l | tail -1

【讨论】:

  • 这不会为您提供总数,而只是针对单个文件。
  • 你说得对,我误会了 -exec 作用于单个文件并且不会提供总数(除非我们使用一些讨厌的 awk)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-12
  • 1970-01-01
相关资源
最近更新 更多