Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'advocate': 0.07; 'subject:help': 0.08; 'clause': 0.09; 'except:': 0.09; 'input,': 0.09; 'style.': 0.09; 'terminates': 0.09; 'try:': 0.09; '9:15': 0.16; '>>on': 0.16; '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; 'normally': 0.19; 'thu,': 0.19; '>>>': 0.22; 'programming': 0.22; 'separate': 0.22; 'print': 0.22; 'error': 0.23; "shouldn't": 0.24; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'chris': 0.29; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'fri,': 0.33; 'comment': 0.34; 'except': 0.35; 'done.': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'useful': 0.36; 'two': 0.37; 'generic': 0.38; 'writes': 0.38; 'to:addr:python- list': 0.38; 'fact': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'issues,': 0.61; 'mentioned': 0.61; 'simply': 0.61; "you're": 0.61; 'more': 0.64; 'note:': 0.66; 'default': 0.69; 'bare': 0.84; '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=T7ofyc74KWMQbDIxtuyxoVN+S55I3iNy988WQCrHpAM=; b=YxHUsC6Y66V/xTLsP3vjb/8xE8N+6IfuL7LBR/Jt4DQfcpcPecfSi2Hh1USjce9h/n Oas4gD4OHBSJl7cv4jLjFmtcQ0YVzPjrRo/ewgH5920fRpLtYkykjQmseQ2NTt9YrMWS EtP0fB8ZRwgIJV7bafTUcvC5wLxZuX3tYCNX+6069xGbKWHPIFl3Mdx85/rlTXJwY34m rGJXO/AijDJhEBU9MoKwFE3hlFfOOKB0E8ha5UASlQKkaJXsL+IXftFyInq9pIJGPDak w5yVFKnrkdJo+HXTd8yNMpIbMWXoNrq/VCez4LM0rHB0UcmhjxO6foMCIFltrWEzmSr+ BxnA== MIME-Version: 1.0 X-Received: by 10.68.231.71 with SMTP id te7mr44982pbc.203.1380869151244; Thu, 03 Oct 2013 23:45:51 -0700 (PDT) In-Reply-To: References: <77bde84a-b0ce-4061-bb2e-e6cd23f4282c@googlegroups.com> Date: Fri, 4 Oct 2013 16:45:51 +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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380869161 news.xs4all.nl 15887 [2001:888:2000:d::a6]:39753 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55453 On Fri, Oct 4, 2013 at 9:15 AM, Dennis Lee Bieber wrote: > On Thu, 3 Oct 2013 10:25:47 +1000, Chris Angelico > declaimed the following: > >>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. >> > 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