Efficency help for a Calculator Program

Chris Angelico rosuav at gmail.com
Wed Oct 2 20:25:47 EDT 2013


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.

ChrisA



More information about the Python-list mailing list