from operator import methodcaller
class Cases:
def methodA():
pass
def methodB():
pass
def main():
case = Cases()
for func in dir(Cases):
if not func.startswith("__"):
methodcaller(func)(case)
main()
會先后執行methodA()和methodB(),不用case.methodA();case.methodB()分別調用,適合類方法較多時需要執行多有方法時使用。