[Python] 显示当前目录所有py文件的类名和函数名 →→→→→进入此内容的聊天室

来自 , 2020-12-10, 写在 Python, 查看 109 次.
URL http://www.code666.cn/view/36455d3b
  1. import os
  2. import sys
  3.  
  4. def Show_file():
  5.     print "lines    filename"
  6.     for i in os.listdir(os.getcwd()):
  7.         if os.path.isfile(i) and not i.startswith("__init__"):
  8.             print os.popen('wc -l %s' % i).read().split('\n')[0]
  9.     print ''
  10.  
  11. def Query_file():
  12.     filename = raw_input('Input the one filename show above[q to quit]:')
  13.     if filename == 'q':
  14.         sys.exit()
  15.  
  16.     file = open(filename,'r').readlines()
  17.     print '\n\n'
  18.     for i in file:
  19.         if i.startswith('class') or i.startswith('def') or i.startswith('    def'):
  20.             print i,
  21.  
  22.  
  23. if __name__ == '__main__':
  24.     Show_file()
  25.     Query_file()
  26. #//python/1172

回复 "显示当前目录所有py文件的类名和函数名"

这儿你可以回复上面这条便签

captcha