Python convert args to kwargs

前端 未结 6 1055
南方客
南方客 2021-02-05 07:57

I am writing a decorator that needs to call other functions prior to call of the function that it is decorating. The decorated function may have positional arguments, but the f

6条回答
  •  无人共我
    2021-02-05 08:14

    Any arg that was passed positionally will be passed to *args. And any arg passed as a keyword will be passed to **kwargs. If you have positional args values and names then you can do:

    kwargs.update(dict(zip(myfunc.func_code.co_varnames, args)))
    

    to convert them all into keyword args.

提交回复
热议问题