John Yeung wrote:
On Sep 29, 1:15 pm, Carl Banks <pavlovevide...@gmail.com> wrote:
Hmm, I wonder if Python should emit a warning if an else is
used on a for block with no break inside.  I don't think the
else can be invoked in any other way.  As a bonus it could
catch some cases where people mistakenly use it thinking it
will execute [only] when there are no iterations.

[Edit from Duncan Booth]

I would definitely be in favor of a warning.  Yes, people should read
the docs more carefully, and yes, it would cost a certain amount of
annoyance to implement this.  But I don't think it would get in
people's way if they do know how to use else, and I think it would cut
down on the number of questions from mystified beginners, some of whom
are much more aggressive than this particular OP about claiming that
Python is broken (when it's actually behaving as designed).

This sort of warning is appropriate for code checkers like Pylint, Pychecker, but not for the running interpreter.

tjr


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to