[Python-Dev] PEP 303: Extend divmod() for Multiple Divisors
Christian Tismer
tismer@tismer.com
Thu, 02 Jan 2003 16:57:25 +0100
Paul Hughett wrote:
> Guido wrote:
>
>
>>>Hey, if we'll killing off builtins, I vote for apply().
>>
>
>>Agreed, it's redundant. You can help by checking in documentation
>>that marks it as deprecated and code that adds a
>>PendingDeprecationWarning to it (unfortunately it's so common that I
>>wouldn't want to risk a plain DeprecationWarning).
>
>
> You've lost me here. I've recently written a piece of code that uses
> a lookup table on the name of a file to find the right function to
> apply to it; if I don't use apply for this, what should I use? An
> explicit case statement cannot be dynamically modified; using eval()
> requires a conversion to string (and is arguably even uglier than
> apply).
Since a function is a first class callable object,
you just pick it out of your lookup table
func = look[key]
and call it with the args and kwds which you got,
using the new asterisk syntax:
ret = func(*args, **kwds)
ciao - chris
--
Christian Tismer :^) <mailto:tismer@tismer.com>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/