How to call Python functions dynamically

If don’t want to use globals, vars and don’t want make a separate module and/or class to encapsulate functions you want to call dynamically, you can call them as the attributes of the current module:

import sys
...
getattr(sys.modules[__name__], "clean_%s" % fieldname)()

Leave a Comment