[Tutor] Example 2
Gregor Lingl
glingl@aon.at
Wed Dec 11 21:23:01 2002
Emil Styrke schrieb:
>>... apply(func, (arg,))
>>
>>
>
>The apply function is a concept borrowed from functional programming
>(e.g. Lisp).
>
>
>
>>>>apply(echo, ('Spam!',))
>>>>
>>>>
>
>which will then call the function echo with the argument 'Spam!':
>
>
In Python 2.2 you (at least in many cases) can avoid to use apply in
favour of the following
simpler syntax:
>>> def echo(cry):
print '***'+cry+'***'
>>> sch = [(echo,'Spam!'), (echo, 'Ham!')]
>>> for (func, arg) in sch:
print func, arg
func(arg)
<function echo at 0x0093EBB0> Spam!
***Spam!***
<function echo at 0x0093EBB0> Ham!
***Ham!***
>>>
Less hard to follow?
Regards, Gregor
>
>
>>>>echo('Spam!')
>>>>
>>>>
>
>Hope that clears things up a little, for this particular case at
>least!
>
> /Emil
>
>
>
>>...
>>Spam!
>>Ham!
>>
>>
>>--
>>Adam Vardy
>>
>>
>>_______________________________________________
>>Tutor maillist - Tutor@python.org
>>http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>
>_______________________________________________
>Tutor maillist - Tutor@python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
>