Get parameter by name
Michael Hudson
mwh21 at cam.ac.uk
Sat Nov 6 08:03:25 EST 1999
Oleg Broytmann <phd at phd.russ.ru> writes:
> Hello!
>
> I have a function with a long list of arguments:
>
> def f(a1, a2, a3, b1, b2, b3, td, sd, si, ka, num=0, date=None):
> ...body_here...
>
> and I have a list of strings "a1, td, ka". How can I get the value of
> corresponding args? E.g., if I have
>
> x = "ka"
>
> how can I get the value of parameter, the name of which is in x ("ka", in
> this case)?
>
> Oleg.
locals() should do the trick:
def f(x):
return locals()["x"]
Arguments are pretty much identical to local variables.
HTH,
Michael
More information about the Python-list
mailing list