[Python-Dev] accumulator display syntax
Skip Montanaro
skip at pobox.com
Fri Oct 17 16:20:38 EDT 2003
>> Is it supposed to return a generator function which I can assign to a
>> variable (or pass to the builtin function sum() as in your example)
>> and call later, or is it supposed to turn the current function into a
>> generator function (so that each executed yield statement returns a
>> value to the caller of the current function)?
Alex> Neither: it returns an iterator, _equivalent_ to the one that
Alex> would be returned by _calling_ a generator such as
Alex> def xxx():
Alex> for x in S:
Alex> yield x
All the more reason not to like this. Why not just define the generator
function and call it?
While Perl sprouts magical punctuation, turning its syntax into line noise,
Python seems to be sprouting multiple function-like things. We have
* functions
* unbound methods
* bound methods
* generator functions
* iterators (currently invisible via syntax, but created by calling a
generator function?)
* instances magically callable via __call__
and now this new (rather limited) syntax for creating iterators.
I am beginning to find it all a bit confusing and unsettling.
Skip
More information about the Python-Dev
mailing list