break in a module

Chris Angelico rosuav at gmail.com
Fri Jun 17 01:56:58 EDT 2011


On Fri, Jun 17, 2011 at 3:20 PM, Erik Max Francis <max at alcyone.com> wrote:
> Yes, which could be rephrased as the fact that `break` and `continue` are
> restricted to looping control structures, so reusing `break` in this context
> would be a bad idea.

Which is why I believe 'return' would be a better choice, even though
returning a value other than None would make no sense. It would simply
be a restriction, and one that almost nobody would notice - like this:

>>> def f():
	yield 1
	yield 2
	yield 3

	
>>> a=f()
>>> a
<generator object f at 0x00FB4AA8>
>>> a.send(1)
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    a.send(1)
TypeError: can't send non-None value to a just-started generator

ChrisA



More information about the Python-list mailing list