PEP 318

Stephen Horne steve at ninereeds.fsnet.co.uk
Mon Mar 22 14:34:35 EST 2004


On Mon, 22 Mar 2004 08:43:08 -0800, David Eppstein
<eppstein at ics.uci.edu> wrote:

>In article <7xn069t5pr.fsf at ruckus.brouhaha.com>,
> Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:
>
>> Eyal Lotem <gnupeaker at yahoo.com> writes:

>> > You are not supposed to be looking for it, IMHO.
>> > Generators follow the Sequence protocol and are to be
>> > treated as sequences.  Thus, you should simply make it
<snip>
>> But that's bogus.  Python is dynamically typed which means that a
>> normal function can return whatever it wants, sequence or
>> non-sequence.  A generator function can't return anything, it can only
>> yield.
>
>I agree with Eyal.  A generator is a callable that, when called, returns 
>an iterator of the items it generates.  The fact that it's defined using 
>yield syntax instead of using return syntax is irrelevant to the caller.

I agree, but I'd still prefer it if the difference between a generator
and a function was explicit in the definition.


-- 
Steve Horne

steve at ninereeds dot fsnet dot co dot uk



More information about the Python-list mailing list