In Python 2.x (I use 2.7), which is the proper way to use default arguments with *args and **kwargs?
I\'ve found a question on
Sticking quite close to your solution approach while trying to make it more generic and more compact I would suggest to consider something like this:
>>> def func(arg1, arg2, *args, **kwargs):
... kwargs_with_defaults = dict({'opt_arg': 'def_val', 'opt_arg2': 'default2'}, **kwargs)
... #...
... return arg1, arg2, args, kwargs_with_defaults
>>> func('a1', 'a2', 'a3', 'a5', x='foo', y='bar')
('a1', 'a2', ('a3', 'a5'), {'opt_arg2': 'default2', 'opt_arg': 'def_val', 'y': 'bar', 'x': 'foo'})
>>> func('a1', 'a2', 'a3', 'a5', opt_arg='explicit_value', x='foo', y='bar')
('a1', 'a2', ('a3', 'a5'), {'opt_arg2': 'default2', 'opt_arg': 'explicit_value', 'y': 'bar', 'x': 'foo'})