import sys, os import numpy as np extn = 'py' # File to store the summary f_summary = 'packageSummary.txt' #----------No further input is needed from the user--------------------- f_i = open(f_summary, "w+") folder = os.getcwd() stg = "\n -----------------------------------------------------------------\n" thisFile = os.path.basename(__file__) for path, subdirs, files in sorted (os.walk(folder) ): for name in files: excludeFile = thisFile in name # Get the absolute path of file s = os.path.join(path, name) # Get the extension with dot ext1 = os.path.splitext(s)[-1].lower() # Get extension of the file without dot ext2 = ext1.partition('.')[2] if ext2.lower() == extn and not excludeFile: print("\n Now processing file: ", s) with open(s) as fp: atrbList = [] ftxt = s+ '\n' f_i.write (ftxt ) while line := fp.readline(): if line.lstrip().lower().startswith("class "): lineX = line.rstrip() + '\n' f_i.write(lineX) if line.lstrip().lower().startswith("self."): atrb = line.split("=") atrbName = atrb[0].split(".") if (len(atrbName) > 0): atrbList.append(atrbName[1].strip()) if line.lstrip().lower().startswith("def "): lineX = line.rstrip() + '\n' f_i.write (lineX) if (len(atrbList) > 0): uniqList = sorted(list(set(atrbList) )) strgAtrb = "Ihis class has attributes: \n" + ', '.join(uniqList) f_i.write(strgAtrb) fp.close() f_i.write(stg) f_i.close()