How to call a python function by using a variable python

I needed to, in a programmatic way, determine the function name and then call the function.

Here’s an example use case. I have a bunch of functions called, [“function1”, “function2”, “function3”, “function4”, etc] Then I have a function that takes a number as a param. Then should return the proper function.

class my_awesome_class():
    def function1(self, number):
        # do something cool

    def function2(self, number):
        # do something cool


    def test_function(self, number, data):
        function_string = ''.join(['function',str(number)])
            t = getattr(my_awesome_class(), function_string)
            return t
        except AttributeError:
            print 'function not found "%s" (%s)' % (function_string, data)