[Python-Dev] repeated keyword arguments
Scott Dial
scott+python-dev at scottdial.com
Sat Jun 28 04:11:03 CEST 2008
Steven D'Aprano wrote:
> It would be nice to be able to do this:
>
> defaults = dict(a=5, b=7)
> f(**defaults, a=8) # override the value of a in defaults
I can't help but think that would be difficult coding convention to use.
However, I'm considerably less bothered by:
def f_with_defaults(**kw):
defaults = dict(a=5, b=7)
defaults.update(kw)
return f(**defaults)
f_with_default(a=8)
The only way f(**defaults, a=8) would be useful is if it happens a lot,
and in that case, it's just as good of a candidate for being made into a
function itself. I see this pattern all the time, and given that
"f_with_defaults" probably has some semantic meaning, it probably would
be nice to give it it's own name ("g").
Just my 2 cents.
--
Scott Dial
scott at scottdial.com
scodial at cs.indiana.edu
More information about the Python-Dev
mailing list