newbie question: apply()

Chris Rebert clp at rebertia.com
Sat Oct 4 11:40:47 CEST 2008


On Sat, Oct 4, 2008 at 2:25 AM, TK <tokauf at web.de> wrote:
> HI,
>
> I need an example for the usage of the apply()-function. Can you help me?

Don't use the apply() function, it's deprecated and unnecessary thanks
to Python's enhanced calling syntax, which is described in depth on
http://www.python.org/doc/2.5.2/ref/calls.html
apply() was used to call an arbitrary function with arbitrary arguments.
This can now be done by e.g:

pos_args = ["spam", 1, [3]]
kwd_args = {"b":7, "c":9}
result = some_function(*pos_args, **kwd_args)

Which is equivalent to:
result = some_function("spam", 1, [3], b=7, c=9)

Which was equivalent to:
result = apply(some_function, pos_args, kwd_args)

Cheers,
Chris

>
> Thanks.
>
> o-o
>
> Thomas
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list