Calling a function, arguments in a dict ??

Gerrit Holl gerrit at nl.linux.org
Mon Jun 23 05:22:48 EDT 2003


Tom Hanks wrote:
> "Thomas Weholt" <2002 at weholt.org> wrote in message news:<wYpJa.8525$Hb.148440 at news4.e.nsc.no>...
> > If I got a dictionary with a bunch of key/values I want to use as named
> > arguments for a function, how do I do that?
> > 
> 
> The 'apply' builtin function is designed to handle this.
> 
> >>> argDict = {'num':10, 'dom':2}
> >>> def ratio(num, dom):
> ... 	return num/dom
> ... 
> >>> apply(ratio, [], argDict)
> 5

Note that apply is no longer necessary now that you can use
func(*args, **kwargs).

yours,
Gerrit.

-- 
42. If any one take over a field to till it, and obtain no harvest
therefrom, it must be proved that he did no work on the field, and he must
deliver grain, just as his neighbor raised, to the owner of the field.
        -- 1780 BC, Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
	http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
	http://www.sp.nl/





More information about the Python-list mailing list