**kwds behavior?

Terry Reedy tjreedy at udel.edu
Tue Sep 2 18:04:05 CEST 2003


"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.

What do you mean 'not work'.  What was your output and what did you
expect?

>It would be alot cooler if there was a way to not have to have
> the function defined with the variable name.

I don't understand your meaning here.

It really seems to me
> that the 3rd function should work. Does anyone know how to
accomplish
> something like this.

Again, what is 'this'?

> def testKeywords1 (**kwds):
> print x

If you want posted code to be read with indents by everybody, use
space instead of tab to indent.  It's your choice to limit readership
or not.

>
> def testKeywords2 (**kwds):
> locals().update(kwds)

Above line has same effect as 'pass' for reason John Roth quoted.

> print x
>
> def testKeywords3 (**kwds):
> locals().update(kwds)
> def testNested():
> print x
> testNested()
>
> dict = {}
> dict['x'] = 5
> # doesn't work

I usually expect 'doesn't work' to apply to the line above that I just
read -- just as this response applies to the line quoted above.  I
suspect you meant 'below doesn't work', whatever 'doesn't work means.
The alternative way to reverse the 'pointer' is to leave a space above
and none below.

> testKeywords1(**dict)
> # doesn't work
> testKeywords2(**dict)
> # doesn't work
> testKeywords3(**dict)

If you don't get your question answered with above, try again with
different words.

Terry J. Reedy






More information about the Python-list mailing list