**kwds behavior?

John Roth newsgroups at jhrothjr.com
Tue Sep 2 11:27:31 EDT 2003


The description of the locals() function is:

Update and return a dictionary representing the current local symbol table.
Warning: The contents of this dictionary should not be modified; changes may
not affect the values of local variables used by the interpreter.

Note that this implies that the dictionary is essentially
read only. What you're trying to do shouldn't work.

John Roth

"Paradox" <JoeyTaj at netzero.com> wrote in message
news:924a9f9c.0309020652.212c54eb at posting.google.com...
> Why does the following attempts to pass in keywords arguments not
> work. It would be alot cooler if there was a way to not have to have
> the function defined with the variable name. It really seems to me
> that the 3rd function should work. Does anyone know how to accomplish
> something like this.
> def testKeywords1 (**kwds):
> print x
>
> def testKeywords2 (**kwds):
> locals().update(kwds)
> print x
>
> def testKeywords3 (**kwds):
> locals().update(kwds)
> def testNested():
> print x
> testNested()
>
> dict = {}
> dict['x'] = 5
> # doesn't work
> testKeywords1(**dict)
> # doesn't work
> testKeywords2(**dict)
> # doesn't work
> testKeywords3(**dict)






More information about the Python-list mailing list