Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed0.kamp.net!newsfeed.kamp.net!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'advocate': 0.07; 'subject:help': 0.08; 'except:': 0.09; 'happen,': 0.09; 'input,': 0.09; 'terminates': 0.09; 'try:': 0.09; 'emit': 0.16; 'emits': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sys.exit(1)': 0.16; 'terminate.': 0.16; 'values?': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'programming': 0.22; 'print': 0.22; 'error': 0.23; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'something': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'useful': 0.36; 'generic': 0.38; 'to:addr:python- list': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'simply': 0.61; "you're": 0.61; 'default': 0.69; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=7zkskGtbifkNma4TeOyloWJSztzix1+VqUUZ9/qBWvc=; b=MdLVb0v5CiCA7QCJS56+HSpMg4KsC2VX9AtIzR2Wwbv7PrDtbHC1CfFHg0NlTAG/QU VcXWVzTCY/7MAvWrrh2T+V5HofWL5N7+KXqD1QH1cL9P7eDh3VaI/xitnNx9V2hWfRST rBX8HtJyA0ykPwstvqnZGcOqP+XSPVz4pb/Go7eDPgCAW4zkoc+DH1nyWu5mSTl/AUf8 MYj3yOwc2A1HL4xBVCb5YtJ2ppD/E41k4c42hdFlalp4Hq39U5MBf7Bn9yGZffz+9iI5 fbDhD14UY9ldseEL5lO3f6oH5SxHO9TFTmqRiIuGjnlHF4HHOvTaghZ1pHOc4YrvFtYP 8xLg== MIME-Version: 1.0 X-Received: by 10.68.130.131 with SMTP id oe3mr49712pbb.186.1380759948091; Wed, 02 Oct 2013 17:25:48 -0700 (PDT) In-Reply-To: References: <77bde84a-b0ce-4061-bb2e-e6cd23f4282c@googlegroups.com> Date: Thu, 3 Oct 2013 10:25:47 +1000 Subject: Re: Efficency help for a Calculator Program From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 15 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380759957 news.xs4all.nl 15863 [2001:888:2000:d::a6]:54820 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55393 On Thu, Oct 3, 2013 at 9:47 AM, Dennis Lee Bieber 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