passing **kwargs to a function

Erik Max Francis max at alcyone.com
Tue Mar 11 22:46:31 EST 2003


Bob Roberts wrote:

> def a(*args, **kwargs):
>     print args,kwargs
>     b(kwargs)
	...
> I am trying to pass int b() the exact same keyword arguments that were
> passed into it.  As you can see, it does't arrive in ths same way.  I
> want the kwargs variable inside a() and b() to be exactly the same.
> How do I do that?

Inside a, kwargs is just a local variable that happens to be a
dictionary.  So when you call b(kwargs), you're just calling b with a
dictionary object as the first argument.  What you meant was:

	b(**kwargs)

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ Who, my friend, can scale Heaven?
\__/ _The Epic of Gilgamesh_
    EmPy / http://www.alcyone.com/pyos/empy/
 A templating system for Python.




More information about the Python-list mailing list