"Steven D'Aprano" <[EMAIL PROTECTED]> 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
> 
> but unfortunately that gives a syntax error. Reversing the order would 
> override the wrong value. So as Python exists now, no, it's not 
> terribly useful. But it's not inherently a stupid idea.

There is already an easy way to do that using functools.partial, and it is 
documented and therefore presumably deliberate behaviour "If additional 
keyword arguments are supplied, they extend and override keywords."

>>> from functools import partial
>>> def f(a=1, b=2, c=3):
        print a, b, c

        
>>> g = partial(f, b=99)
>>> g()
1 99 3
>>> g(a=100, b=101)
100 101 3



_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to