【Python】申请软著之统计JavaWeb项目代码行数
软著这东西有点奇葩,不能多说。参考其它的博客,增加了源代码文件编码格式的设置,可自己增加要统计的代码格式,在 typeList的中括号里增加就行了。import osprojectDir='C:\\Users\\Administrator\\Desktop\\1\\myproject'typeList = ['java']#统计的源代码文件格式fileCode = 'UTF-8'#源代码文件的编码
·
软著这东西有点奇葩,不能多说。
参考其它的博客,增加了源代码文件编码格式的设置,可自己增加要统计的代码格式,在 typeList 的中括号里增加就行了。
import os
projectDir='C:\\Users\\Administrator\\Desktop\\1\\myproject'
typeList = ['java'] #统计的源代码文件格式
fileCode = 'UTF-8' #源代码文件的编码格式
def getFileList(projectDir):
fileList = []
for parent,dirNames,fileNames in os.walk(projectDir):
for filename in fileNames:
ext = filename.split('.')[-1]
if ext in typeList:
fileList.append(os.path.join(parent,filename))
return fileList
def countLine(fileName, fileCode):
count = 0
for file_line in open(fileName,'r',encoding=fileCode).readlines():
if file_line != '' and file_line != '\n':
count += 1
print (fileName + '----' , count)
return count
if __name__ == '__main__' :
fileList = getFileList(projectDir)
totalCnt = 0
for sourcefile in fileList:
totalCnt = totalCnt + countLine(sourcefile, fileCode)
print ('Total Lines:',totalCnt)
下一步自动生产软著申请的源代码文档,即前3000行代码和后3000行代码。

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)