I have a list of methods and I can call all of the methods at once with another method.
How can I call the method which contains all while leaving out certain items(or methods) from the list? I can currently specify one to leave out. I am not sure how to leave out more than one. Here is what I am working with:
class SomeClass:
def method_a(self):
print('method_a')
def method_b(self):
print('method_b')
def method_c(self):
print('method_c')
def method_runner(self, skip_name='' ):
for m in [self.method_a, self.method_b, self.method_c]:
if m.__name__ != skip_name:
m()
Now I can do this:
>>> some_obj = SomeClass()
>>> some_obj.method_runner('')
method_a
method_b
method_c
>>> some_obj.method_runner('method_a')
method_b
method_c
>>> some_obj.method_runner('method_b')
method_a
method_c
Is there a way to do something like this?
class SomeClass:
def method_a(self):
print('method_a')
def method_b(self):
print('method_b')
def method_c(self):
print('method_c')
def method_runner(self, skip_name='', skip_name2='', skip_name3=''):
for m in [self.method_a, self.method_b, self.method_c]:
options = [skip_name, skip_name2, skip_name3]
for o in options:
if m.__name__ != o:
m()
And specify more than one method to get an outcome such as:
>>> some_obj.method_runner('method_a', 'method_c')
method_b