Newbie question: How do I add elements to **kwargs in a function?

Aaron Garrett aaron.lee.garrett at
Tue Mar 17 03:48:22 CET 2009

I have spent quite a bit of time trying to find the answer on this
group, but I've been unsuccessful. Here is what I'd like to be able to

def A(**kwargs):
    kwargs['eggs'] = 1

def B(**kwargs):

def C(**kwargs):

I'd like to be able to make a call like:


and have it print
{'spam': 0, 'eggs': 1}

But it doesn't do that. Instead, it gives
{'spam': 0}

I was under the impression that kwargs is passed by reference and,
since I'm only modifying it (rather than making it point to something
else) that the changes would be reflected back out to the thing being
passed in.

So, why doesn't this work the way I expect it to? And, is there some
other way to make this work to accomplish the same goal?

Thank you in advance,

More information about the Python-list mailing list