I have a module that I import to my main application called pageprocs.py with a collection of functions in it that generate different content and return it in a string. pageprocs is supposed to be a way of allowing authenticated users to create plugins for the different content type.
I then have a list of strings: [‘check_stats’, ‘build_table’, ‘build_ace’] which are the names of some functions in pageprocs. I need to execute the functions in the order they are in the list and can’t find a way of doing this without using exec():
for i in list_of_funcs:
exec('pageprocs.%s()' % i)
This just seems like a seriously bad idea to me and not easy to catch any exceptions in users code. Is there an alternative to running code this way or does anybody have suggestions on user-defined content generation (I ask this because I maybe approaching the whole situation wrong).
The
lambda: Nonepart is optional, but will preventAttributeErrorbeing raised if the specified function doesn’t exist (it’s an anonymous do-nothing function).