[Tutor] Tutor Digest, Vol 15, Issue 40

J. Gabriel Schenz jgschenz at yahoo.com
Wed May 18 12:05:47 CEST 2005


>At 02:17 PM 5/12/2005, Bernard Lebel wrote:
>>Just a generic question: why one would use apply()?
>>
>>In Learning Python, on page 357, there is an example of generating an
>>instance using apply():
>>
>>class A:
>>       def __init__( self, number ):
>>              self.number = number
>>
>>a = apply( A, 3 )
>>What is the benefit of doing this over simply creating an instance "the 
>>usual way":
>>a = A( 3 )
>
>No benefit. See 2.2 Non-essential Built-in Functions in the Python Library 
>Reference. 'Use of apply() is not necessary since the ``extended call 
>syntax,'' as used in the last example, is completely equivalent."
>
>Bob Gailer

Now, I am new to Python as well, but it seems like apply might not be
completely superfluous.  I was thinking that if one were using a functional
programming style, and had to apply a function determined at runtime to an
argument, then one could use this apply to do so.  Granted, you could also
have a dictionary of functions and call the function required as determined
at runtime, but this is stylistically different.

If I am off base on this, I would appreciate someone explaining why.  That
way I can learn this elegant language better.

Regards,
Gabe




More information about the Tutor mailing list