break in a module

Eric Snow ericsnowcurrently at gmail.com
Fri Jun 17 02:25:43 EDT 2011


On Thu, Jun 16, 2011 at 11:56 PM, Chris Angelico <rosuav at gmail.com> wrote:
> 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:
>

I'd say let's not bikeshed on the name when the merits of "breaking"
out of a module's execution haven't been established, but what's the
point.  <wink>

-eric

>>>> 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
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list