I'm cleaning some smeared data for which I want to automate things a bit. That is, I want a script to have some predefined cleaning functions put in order of how the data should be cleaned, and I designed a decorator to retrieve these functions from a script using this solution:
from inspect import getmembers, isfunction
import cd # cleaning module
functions_list = [o[0] for o in getmembers(cd) if isfunction(o[1])]
This works extremely good. However, it does retrieve the functions in a different order (by name)
For reproducibility purposes, consider the following cleaning module as cd
:
def clean_1():
pass
def clean_2():
pass
def clean_4():
pass
def clean_3():
pass
The solution outputs:
['clean_1', 'clean_2', 'clean_3', 'clean_4']
Where it needs to be:
['clean_1', 'clean_2', 'clean_4', 'clean_3']
Other solutions to the main problem are acceptable (performance is considered though).