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

Cameron Horn camhorn at mac.com
Wed Nov 13 17:02:18 EST 2002


> What is the semantic of "an empty generator", i.e. what does it mean? A
> generator that never generates any values?

Yes, absolutely.  I find these empty things to be very useful, both as placeholders for things that I'll implement later and places where I mean to have nothing happen.

> Would this fulfill your requirement? (And not upset you so much :-)
>
> def nullgen():
>    raise StopIteration
>    yield "never called"

> >>> for x in nullgen():
> ...     print x
> ...
> >>>
> >>>

I appreciate your attempt to soothe my delicate sensibilities ;), but no.  The fact that a line that I know isn't being executed changes my function, not just in a behavioral way but a structural one, gives me the willies.

> It doesn't bother me.

Syntactic cruft bothers me; that's why I like Python so much.

If generators acted like other functions (i.e., could be used interchangably) I'd have no problem.  But they can't, so I'm bothered.




More information about the Python-list mailing list