From another question, this may help:
import inspect
functions_used = []
class DataCleanAndMerge:
def __init__(self):
self.fnumb = 1
self.snumb = 1
def plus(self):
func_name = inspect.currentframe().f_code.co_name
if func_name not in functions_used:
functions_used.append(func_name)
return self.fnumb + self.snumb
def equals(self):
func_name = inspect.currentframe().f_code.co_name
if func_name not in functions_used:
functions_used.append(func_name)
return self.fnumb == self.snumb
And if you want to save that information, even after execution is finished, just keep the data in a file. You can read it into a list at the beginning, and then write the list to the file when you're done:
import inspect
import os.path
class DataCleanAndMerge:
def __init__(self):
self.fnumb = 1
self.snumb = 1
def plus(self):
func_name = inspect.currentframe().f_code.co_name
if func_name not in functions_used:
functions_used.append(func_name)
return self.fnumb + self.snumb
def equals(self):
func_name = inspect.currentframe().f_code.co_name
if func_name not in functions_used:
functions_used.append(func_name)
return self.fnumb == self.snumb
if __name__ == '__main__':
functions_used = []
methods_file = "methods_used.txt"
# Check if file exists. Create it if needed.
if not os.path.exists(methods_file):
with open(methods_file, "w") as f: pass
with open(methods_file, "r") as fin:
for x in ' '.join(fin.read().split('\n')).split():
functions_used.append(x)
print('Functions Used: {}'.format(functions_used))
c = DataCleanAndMerge()
if len(functions_used)>0:
c.equals()
c.plus()
print('Functions Used: {}'.format(functions_used))
with open(methods_file, "w") as fout:
for x in functions_used:
fout.write("{}\n".format(x))
There are a few other options, but this seems to be the safest way to get a list of functions used. Of course, if you are trying to get the list without actually editing the class and its methods, this will not be of much use.