0

I have the following code to use * argument for a function.

inputs = [fill(input) for input in input_shapes]
# num_runs is an integer 
def bench(num_runs):
    inputs.append(num_runs) # can I remove this?
    handle_type(*inputs)
    del inputs[-1] # can I remove this? 

I want to know a better way to handle *inputs, so I don't have to call append and del every time.

I tried a simple example:

inputs = [1, 2, 3]
inputs2 = [1, 2] 
def Test(a, b, c):
     print (a, b, c)


Test(*inputs) # works 
Test(*inputs2, 3) # SyntaxError: only named arguments may follow *expression

I found a solution here Unpacking arguments: only named arguments may follow *expression and it is what I am looking for.

Zack
  • 1,205
  • 2
  • 14
  • 38

1 Answers1

2

You should be able to do this, at least in reasonably recent Python 3 versions:

inputs = [fill(input) for input in input_shapes]
def bench(num_runs):
    handle_type(*inputs, num_runs)
Samuel Dion-Girardeau
  • 2,790
  • 1
  • 29
  • 37