Python 2.4 interactive session: Py> class Blah: ... def __iter__(self): ... yield "Test" ... Py> args = Blah() Py> apply(len, args) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: apply() arg 2 expected sequence, found instance Py> len(*args) 4 Py> class Blah(object): ... def __iter__(self): ... yield "Test" ... Py> args = Blah() Py> apply(len, args) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: apply() arg 2 expected sequence, found Blah Py> len(*args) 4
And you're right, there is a behavioural difference - apply() expects a real sequence, whereas the extended function call syntax accepts any iterable.
However, there's also a bug in your demo code:
Py> def YieldTest(): ... yield "Test" ... Py> x = YieldTest().__iter__ Py> list(x()) ['Test'] Py> list(x()) []
Your failing case with len(*args) was due to the iterator having already been consumed :)
Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list