My (late) beef with Simple Generator syntax (PEP 255)

Cameron Horn camhorn at mac.com
Wed Nov 13 17:26:14 EST 2002


 
On Wednesday, Nov 13, 2002, at 02:19PM, <sismex01 at hebmex.com> wrote:

>> From: Cameron Horn [mailto:camhorn at mac.com]
>> Sent: Wednesday, November 13, 2002 4:20 PM
>>  
>> On Wednesday, Nov 13, 2002, at 02:16PM, David Eppstein 
>> <eppstein at ics.uci.edu> wrote:
>> 
>> >On 11/13/02 2:11 PM -0800 Cameron Horn <camhorn at mac.com> wrote:
>> >>> What I wonder is, why does it need to be a generator?  
>> What's wrong with
>> >>> def foo(): return ( )
>> >>> ?
>> >>
>> >> You're right if it's a one-time thing.  However, if I've got a
>> >> scaffolding like this, then it matters.
>> >>
>> >> def process_generator(function):
>> >>    for x in function():
>> >>       print x
>> >
>> >How does the function foo() I defined above fail to work in this 
>> >scaffolding?
>> 
>> In the "TypeError: iteration over non-sequence" sort of way.
>>
>
>An empty tuple is a sequence also;
>
>the "return ( )" thing is returning an empty tuple,
>not "None".  You can make it clearer by using
>"return tuple()" rather than "return ()".

Oops.  Missed those parentheses.  Then it is completely useful, unless you end up using the "next" method.




More information about the Python-list mailing list