这是一个实用性非常强的Python代码。有工作时会遇到程序代码量特别大的情况,其继承性太强,同时定义的类和函数也有太多,不方便查找。为了工作需要只好写个脚本程序查看显示当前目录下所有py文件类名和函数的方法。
import os
import sys
def Show_file():
print "lines filename"
for i in os.listdir(os.getcwd()):
if os.path.isfile(i) and not i.startswith("__init__"):
print os.popen('wc -l %s' % i).read().split('\n')[0]
print ''
def Query_file():
filename = raw_input('Input the one filename show above[q to quit]:')
if filename == 'q':
sys.exit()
file = open(filename,'r').readlines()
print '\n\n'
for i in file:
if i.startswith('class') or i.startswith('def') or i.startswith(' def'):
print i,
#www.iplaypy.com
if __name__ == '__main__':
Show_file()
Query_file()
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/code/base/b2325.html
相关文章 Recommend