python小程序查看自己写了多少行代码
2017-08-05 00:09
225 查看
近两个月白天都在加班,晚上在恶补深度学习的知识以及学习tensorflow,后面学着学着感觉paddlepaddle框架(百度继Echarts外又一良心巨作!)也是不错的选择,有很详细的说明文档,对深度学习神经网络感兴趣的同学可以作为入门的选择,个人还未尝试,后期有时间可能会针对paddlepaddle进行学习并写些心得。
好了言归正传,5月低的时候临近毕业,突发奇想想知道知道大二开始捡起python到现在一共写了多少行代码,也算是给自己一个评定吧。
原理很简单,利用文件夹遍历方式获取.py文件,读取py文件内的行数。
# -*- coding: utf-8 -*- # @Date : 2017-05-25 23:46:39 # @Author : Alan Lau (rlalan@outlook.com) # @Version : Python3.5 import os def fw(path): fileArray = [] for root, dirs, files in os.walk(path): for fn in files: if (fn.split('.'))[-1] == 'py' and r'D:\Sofrware\Python35' not in root: # 判断是否为py文件,因为我的python第三方包安装在了D:\Sofrware\Python35这个路径下,因此跳过这个文件夹 file = str(root+'\\'+fn) fileArray.append(file) return fileArray def ifcode(path): files = fw(path) return files def line_counter(file): counter = 0 try: with open(file, 'rb') as f: content = f.readlines() content = list(filter(lambda line: line != b'\r\n', content)) # 过滤空行 counter = len(content) except Exception as e: counter = 0 pass else: pass finally: pass return counter from datetime import datetime def main(): path = r'D:\\' counter = 0 files = ifcode(path) i = 0 for file in files: i += 1 counter += line_counter(file) if counter > 10*i: print('got %s lines.' % counter) print('u have done %d python files.' % len(files)) print('u have done %d lines code, good luck Alan...' % counter) if __name__ == '__main__': t_s = datetime.now() main() t_e = datetime.now() print('[finished in %s]' % (t_e-t_s))
结果:
4487112行代码……
相关文章推荐
- 写一个程序,统计自己C语言共写了多少行代码。ver2.00
- Python 练习 06 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释
- 【python】查看和添加路径,直接调用自己的代码
- 自己使用总结Python程序代码片段
- 每天一个python小程序 007有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。包括空行和注释,但是要分别列出来。
- Android——查看自己项目有多少行代码
- 写一个程序,统计自己C语言共写了多少行代码,Github基本操作
- 实验 3.1.5 查看代码中各数据存储位置 示例程序: mem_add.c 1. 在自己的机器上运行示例程序。 2. 分析实验结果,图示程序运行时各数据位置。
- 自己使用总结Python程序代码片段
- 根据指定两个日期计算出这些时间内有多少天是周末 php程序函数代码
- 一个极其简洁的Python网页抓取程序,自己主动从雅虎財经抓取股票数据
- python+tkinter编写电脑桌面放大镜程序实例代码
- python聊天程序实例代码分享
- 如何把自己写的python程序给别人用
- 在自己的java代码中编译并运行程序
- xcode反汇编调试iOS模拟器程序(八)反汇编自己的代码来掌握规则
- PYTHON 验证码服务程序代码
- 11周2-2项目 - 存储班长信息的学生类,将Stu类的数据成员的访问权限改为private,你的程序是否能完成要求的功能?如果不行,请修改程序。请不要修改给出的代码,只能修改自己写的代码。
- 通过Py2exe将自己的python程序打包成.exe/.app的方法
- python写的代码行数统计程序