"Andrew Dalke" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Terry Reedy wrote: >> As far as I know, apply(func, args) is exactly equivalent to >> func(*args). > > After playing around a bit I did find one difference in > the errors they can create.
Ok, add 'assuming that func and args are a valid callable and sequence respectively.' Error messages are not part of the specs, and may change for the same code from version to version. >>>> def count(): > ... yield 1 > ... >>>> apply(f, count()) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: apply() arg 2 expected sequence, found generator >>>> f(*count()) > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: len() of unsized object >>>> > > That led me to the following > >>>> class Blah: > ... def __len__(self): > ... return 10 > ... def __getitem__(self, i): > ... if i == 0: return "Hello!" > ... raise IndexError, i > ... >>>> blah = Blah() >>>> len(*blah) > 6 >>>> apply(len, *blah) To be equivalent to len(*blah), this should be apply(len, blah), no *. >>> apply(len, blah) 6 #Py2.2 > Traceback (most recent call last): > File "<stdin>", line 1, in ? > TypeError: len() takes exactly one argument (6 given) >>>> > > Is that difference a bug? In your input, yes ;-) Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list