For example, I've got functions, funcA()
, funcB()
, funcC()
.我想调用这些函数中的每一个,但在每个函数之后,执行一系列其他函数,如 func1()
、func2()
、func3 ()
, func4()
.
我知道我可以:
funcA()
func1()
func2()
func3()
func4()
funcB()
....
或者我可以:
def funcCombined():
func1()
func2()
func3()
func4()
funcA()
funcCombined()
funcB()
funcCombined()
...
但是有没有更好的办法呢?我试着把它们放在一个列表中,比如:
funcs = [funcA(), funcB(), funcC()]
for func in funcs:
x = func
func1()
func2()
func3()
func4()
But it seems to be executing all of the functions in the list and then executing them in the for loop.
执行此操作的最佳方法是什么?
最佳答案
不要在你想要之前调用函数
funcs = [funcA, funcB, funcC]
for func in funcs:
func()
关于Python:如何包装函数调用,而不是函数本身?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47835564/