I have a class and within one of the methods of the class I have a string given from user input which is then mapped to the corresponding method (technically is a str representation of the method). How can I call this method without an instance of the class being created yet, i.e., with self. argument. I've included what I thought would work but it doesn't...
class RunTest():
def __init__(self, method_name):
self.method_name = method_name #i.e., method_name = 'Method 1'
def initialize_test(self):
mapping = {'Method 1': 'method1()', 'Method 2': 'method2()', ...}
test_to_run = getattr(self, mapping[self.method_name])
def method1(self):
....
def method2(self):
....