If these functions are class methods, use dir(self)to list all attributes self.
class C:
def prepare(self):
print(dir(self))
for name in dir(self):
if name.startswith('prepare_'):
method = getattr(self, name)
method()
def prepare_1(self):
print('In prepare_1')
def prepare_2(self):
print('In prepare_2')
C().prepare()
Conclusion:
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'prepare', 'prepare_1', 'prepare_2']
In prepare_1
In prepare_2
Update: if you want to call methods from outside the class C:
obj = C()
for name in dir(obj):
if name.startswith('prepare_'):
m = getattr(obj, name)
print(m)
m()
Conclusion:
<bound method C.prepare_1 of <__main__.C object at 0x7f347c9dff28>>
In prepare_1
<bound method C.prepare_2 of <__main__.C object at 0x7f347c9dff28>>
In prepare_2