Comment on Draft Pep ver 4 -- Psuedo Deprecations of Builtins

Delaney, Timothy tdelaney at avaya.com
Tue Apr 30 22:53:46 EDT 2002


> From: huaiyu at gauss.almadan.ibm.com 
> 
> John Roth <johnroth at ameritech.net> wrote:
> >I strongly disagree about apply(). The only use I've found for it
> >varies the function which it calls, not the parameter lists! Having
> >variable parameter lists doesn't hack it - I need the variable
> >function.
> 
> >>> from math import *
> >>> a = (2.3,)
> >>> for f in [sin, cos, sqrt]: print apply(f, a)
> ... 
> 0.745705212177
> -0.66627602128
> 1.51657508881
> >>> for f in [sin, cos, sqrt]: print f(*a)
> ... 
> 0.745705212177
> -0.66627602128
> 1.51657508881

There can be real advantages to apply being a first-class object though,
which you don't get with the syntax f(*a, **b). apply can be passed around
and used just as any callable.

There is no way I would deprecate apply - esp. if you want code to work on
1.5.2, 2.0, 2.1, 2.2, 2.3 without change (which is still possible for most
code). I appreciate the f(*a, **b) syntax, but I think of it as an
alternative to apply, not a replacement.

Tim Delaney





More information about the Python-list mailing list