原创Python数代码行数代码,原创python代码行数,如下python代码实现
原创Python数代码行数代码,原创python代码行数,如下python代码实现
如下python代码实现数代码行数功能,使用了os模块的walk方法来遍历文件目录,使用enumerate方法来遍历一个代码文件中的所有代码行。
# -*- coding: cp936 -*-import os__author__ = 'byrx.net'def count(path): for r,dirs,files in os.walk(path): for f in files: fileFullPath = os.path.join(r,f) left,ex = os.path.splitext(fileFullPath) ex = ex.lower() if ex in fileTypes.keys(): fileLineCount = 0 with open(fileFullPath) as fileHandler: for index,line in enumerate(fileHandler): if len(line.strip()) == 0: # or line.strip().startswith('#'): continue fileLineCount += 1 print '%s line count is %d' % (fileFullPath,fileLineCount) fileTypes[ex] += fileLineCount for d in dirs: childDir = os.path.join(r,d) count(childDir)root = r'e:\outofmemory\svn\web'#要数行数的文件类型fileTypes = {'.py':0}count(root)for k,v in fileTypes.items(): print '%s line count is %d' % (k,v)
如果你要使用此代码需要修改root变量的值和要数代码文件的扩展名。
相关内容
- Python逐块读取大文件行数的代码,python逐行数代码,py
- python二分查找,python二分,python二分查找[P
- python实现的堆排序算法代码,python堆排序算法,def heap
- Python之SMTP 发邮件,pythonsmtp发邮件,这段代码解释了SM
- Python的默认参数详解,python参数详解,文章的主题不要使
- python操作sqlite3数据库完全代码,pythonsqlite3,# Name: pySn
- python一个简单的lisp实现,pythonlisp,#coding=utf-
- 从 chinadaily 下载 chinadail 的 pdf papger,chinadailpapger,之前
- python将数据库的内容写入excel中,pythonexcel,[Python]代码
- python类的静态方法和类方法示例,python类静态示例,py
评论关闭