[Python-Dev] repeated keyword arguments (original) (raw)
Duncan Booth duncan.booth at suttoncourtenay.org.uk
Wed Jul 2 13:47:02 CEST 2008
- Previous message: [Python-Dev] [issue3214] Suggest change to glossary explanation: "Duck Typing"
- Next message: [Python-Dev] Review needed: proposed fix for 2.6 __hash__ incompatibility (issue 2235)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Steven D'Aprano" <steve at pearwood.info> 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
- Previous message: [Python-Dev] [issue3214] Suggest change to glossary explanation: "Duck Typing"
- Next message: [Python-Dev] Review needed: proposed fix for 2.6 __hash__ incompatibility (issue 2235)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]