0

I have a function from which I would like to pass all arguments to another func. The following example does not work. how can I pass all positional arguments, and kwargs together, assuming they are not optional (I don't want to collect them as *args and/or *kwargs)?

def myfunc(arg1, arg2, arg3 = None, arg4 = None):

    anotherfunc(*args, **kwargs)

Thanks

Kevin
  • 74,910
  • 12
  • 133
  • 166
lihi
  • 1
  • 4
    You will have to do it explicitly, `anotherfunc(arg1, arg2, arg3, arg4)`. You can't just expect them to magically end up in `*args` and `**kwargs`. – jonrsharpe Oct 14 '15 at 14:52
  • You should consider just passing a dictionary as a position argument, which will allow you to access all the values by name in the main function, and pass them on in one-shot to the other function. – dursk Oct 14 '15 at 15:05
  • @dursk, could you please show me how to do it for my example? Thanks – lihi Oct 14 '15 at 15:11
  • @dursk, that wouldn't allow calls like `myfunc(0, arg2=1)`. – leewz Oct 31 '15 at 07:07

0 Answers0