python - How to read variable number of outputs -
i'm running python 2.7.3. have list of functions invoke each. functions return more 1 outputs. i'd save outputs of functions in list. how can that?
def f1(): return [1,2], [3,4] def f2(): return [5,6] my_outputs = [] my_funcs = [f1, f2] func in my_funcs: output_list* = func() # work? # a,b,c... = func() my_outputs.extend(output_list) print my_outputs [[1,2], [3,4], [5,6]]
you can check return type isinstance
, although it's not pythonic.
my_outputs = [] my_funcs = [f1, f2, f3] func in my_funcs: result = func() if isinstance(result, tuple): my_outputs.extend(result) else: my_outputs.append(result)
Comments
Post a Comment