Passing parameters using **kargs
Fuzzyman
michael at foord.net
Tue Jun 8 09:10:00 EDT 2004
tkpmep at hotmail.com (Thomas Philips) wrote in message news:<b4a8ffb6.0406071858.24dbb8ee at posting.google.com>...
> I want to access parameters that are passed into a function using the
> **kargs idiom. I define f(**kargs) via
>
> def f(**kargs):
> print kargs
> .
> .
>
> the keyword arguments are converted to a dictionary, so that if I type
> f(a=1, b=2, c=3)
>
> the function prints
> {'a': 1, 'b': 2, 'c':3}
>
> Now assume the function has three variables a, b and c to which I want
> to assign the dictionary's values of 'a', 'b' and 'c'. How can I
> assign kargs['a'] to a, kargs['b'] to b, and kargs['c'] to c. Should I
> be trying to construct a string representation of each variable's name
> and using that as a key, or am I just thinking about this the wrong
> way?
>
> Thomas Philips
MY reading of what you say is - I have three variable a, b and c.. and
a dictionary, kargs, with keys 'a', 'b' anc 'c'. I want to assign the
contents of kargs to the three variables. The specific case is surely
? :
a = kargs['a']
b = kargs['b']
c = kargs['c']
or is it the more general case you're after ?
I think I'm misunderstanding you I'm afraid....
Fuzzyman
http://www.voidspace.org.uk/atlantibots/pythonutils.html
More information about the Python-list
mailing list