Calling a function with unknown arguments?

Grant Edwards grante at visi.com
Thu Mar 8 00:14:24 CET 2007


On 2007-03-07, Rob <crowell at mit.edu> wrote:
> I can get a list of a function's arguments.
>>>> def bob(a, b):
> ...     return a+b
> ...
>>>> bob.func_code.co_varnames
> ('a', 'b')
>
> Let's say that I also have a dictionary of possible arguments for this
> function.
>>>> possible = {'a':10, 'b':5, 'c':-3}
>
> How do I proceed to call bob(a=10, b=5) with this information?

bob(a=possible['a'],b=possible['b'])

-- 
Grant Edwards                   grante             Yow!  BRILL CREAM is
                                  at               CREAM O' WHEAT in another
                               visi.com            DIMENSION...



More information about the Python-list mailing list