Efficency help for a Calculator Program

Chris Angelico rosuav at gmail.com
Fri Oct 4 02:45:51 EDT 2013


On Fri, Oct 4, 2013 at 9:15 AM, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Thu, 3 Oct 2013 10:25:47 +1000, Chris Angelico <rosuav at gmail.com>
> declaimed the following:
>
>>On Thu, Oct 3, 2013 at 9:47 AM, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>>>     try:
>>>         numItems = int(raw_input("\n\nHow many values? "))
>>>     except:     #naked exception is not really good programming
>>>         print "Invalid input, exiting..."
>>>         sys.exit(1)
>>
>>Please don't _ever_ advocate this programming style! Wrapping
>>something in a try/except that emits a generic message and terminates
>>is a bad idea - the default behaviour, if you simply let the exception
>>happen, is to emit a very useful message and terminate. Never test for
>>any error condition you're not prepared to handle, as the BOFH advised
>>his boss.
>>
>         Note: I DID include a comment that this was NOT good style.

You mentioned that bare except is a problem; I'm more looking at the
fact that the except clause simply writes a message and terminates.
They're two separate issues, both bad style.

I know _you_ know it's bad style; but someone reading over this needs
to be aware that this shouldn't normally be done.

ChrisA



More information about the Python-list mailing list