调用可调用对象的列表



假设我有一个可调用对象列表:

[<Python.Proto object at 0x1046ff940>,
<Database.Proto object at 0x10540c518>]

我将如何遍历执行每个可调用对象的列表,将结果留在列表中?

对于列表理解,这是相当简单的,例如:

results = [f() for f in callables]
def foo():
   pass
def bar():
   pass
l = [str, map, foo, bar]
result = [call() for call in l]

您必须确保要传递给每个函数的参数可以将其作为dict

最新更新