#提取文件中的方法名称 # -*- coding:utf-8 -*- def Query_Method(filepath): file = open(filepath,'r',encoding= 'UTF-8').readlines() print ('\n\n') str = "" for i in file: if i.startswith('def') or i.startswith(' def'): str += i[8:-4] # print(str) str += "," # print(str) return str if __name__ == '__main__': #初始化数据 str = Query_Method("..\\data\\test_InitializationData.py") arr = str.split(",") for i in range(0,len(arr)): if arr[i] !="": getattr(InitializationData,arr[i])()