第 0007 题:有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。
2016-11-24 11:38
1156 查看
第 0007 题:有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。
def get_code_lines(inputpath):
"""
"""
if os.path.isdir(inputpath) == False:
print "input not directory!"
sys.exit()
os.chdir(inputpath)
count = {}
count["code_num"] = 0
count["space_num"] = 0
count["comment_num"] = 0
for one_file in os.listdir(os.getcwd()):
print one_file
get_file_code_num(one_file, count)
print count
def get_file_code_num(one_file, count):
"""
"""
if os.path.isfile(one_file) == False:
print "is not file"
sys.exit()
for line in open(one_file, "r"):
if "#" in line or "/*" in line or "*/" in line:
count["comment_num"] += 1
elif len(line) != 0:
count["code_num"] += 1
else:
count["space_num"] += 1
def get_code_lines(inputpath):
"""
"""
if os.path.isdir(inputpath) == False:
print "input not directory!"
sys.exit()
os.chdir(inputpath)
count = {}
count["code_num"] = 0
count["space_num"] = 0
count["comment_num"] = 0
for one_file in os.listdir(os.getcwd()):
print one_file
get_file_code_num(one_file, count)
print count
def get_file_code_num(one_file, count):
"""
"""
if os.path.isfile(one_file) == False:
print "is not file"
sys.exit()
for line in open(one_file, "r"):
if "#" in line or "/*" in line or "*/" in line:
count["comment_num"] += 1
elif len(line) != 0:
count["code_num"] += 1
else:
count["space_num"] += 1
相关文章推荐
- 第 0007 题:有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。
- 每天一个python小程序 007有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。
- Python 练习 06 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释
- Python Show-Me-the-Code 第 0007 题 统计代码行数(注释,空行,总行数)小程序
- python 统计一个目录下代码的行数、空行和注释
- 用python统计代码行的示例(包括空行和注释)
- 用python统计代码行(包括空行和注释)
- python写的统计PYTHON文件的(代码行数,空行数,注释行数)小程序
- PHP统计目录下的文件总数及代码行数(去除注释及空行)
- PHP统计目录下的文件总数及代码行数(去除注释及空行)
- PHP统计目录下的文件总数及代码行数(去除注释及空行)
- 统计一下你写过多少代码
- 统计代码行数(包括空行)
- 写一个程序,统计自己C语言共写了多少行代码。ver2.00
- 课程实验一:目标一:输出该目录下指定类型文件(.cs, .java)的个数、文件的总行数、空行数、注释行数、代码行数
- iOS代码统计(空行、注释、代码)
- Java统计目录文件下行数的总和,注释行数的总和,空行数总和
- 利用正则表达式实现统计代码中的注释行、空行、以及代码行的数量。
- 计算java文件有多少行注释行,正常代码行,空白行的程序,swing做的