Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Mon, 21 Mar 2016 13:07:55 +1100 Lines: 40 Message-ID: References: <56e44258$0$1598$c3e8da3$5496439d@news.astraweb.com> <8737rvxs89.fsf@elektro.pacujo.net> <56e7483d$0$1608$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de nNJlg+9iiY1npQhhDnIKbAfmP6VLfMeF6Uc5xuMfrigQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'received:209.85.223': 0.03; '21,': 0.07; 'caller': 0.07; 'except:': 0.07; 'cc:addr :python-list': 0.09; '"can\'t': 0.09; '22,': 0.09; 'exceptions,': 0.09; 'exits': 0.09; 'mark.': 0.09; 'oh,': 0.09; 'raised.': 0.09; 'subject:which': 0.09; 'exception': 0.13; 'def': 0.13; 'file,': 0.15; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'try:': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'are.': 0.22; 'lawrence': 0.22; 'errors': 0.23; 'header:In-Reply- To:1': 0.24; 'mon,': 0.24; 'chris': 0.26; 'figure': 0.27; 'message-id:@mail.gmail.com': 0.27; 'print': 0.30; "can't": 0.32; 'up.': 0.32; 'returned': 0.32; 'open': 0.33; 'skip:d 20': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'so,': 0.35; 'generic': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'received:209': 0.38; 'anything': 0.38; 'skip:p 20': 0.38; 'why': 0.39; 'data': 0.39; 'sure': 0.39; 'mark': 0.40; 'subject:The': 0.61; 'mar': 0.65; 'better.': 0.66; 'picked': 0.66; 'results': 0.66; 'saw': 0.77; 'chrisa': 0.84; 'promptly': 0.84; 'absolutely': 0.88; 'to:none': 0.91 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:cc; bh=VECQAlMEQBzEziMWynewdnnAtoqDKW3dEsYHkkFDRUE=; b=zG/7w+/KZG2bSzYADYEJDZj+H4YLn4Lscih7p16BpQLen1hVmAiRXWT+aRChs88w9K yHZjpK5J3CsQXhw4NGSjNrOGhpImjjK8/t9F4bANiLUnmGfyWKFk+uH9jIpNNUzkhE7k +l/mVxWloLjgeIduWNrveh2QGrZ9+OT0uImks+WwjXhr8DrsbtsjiE+wIotrdX/SGlPI W8kXA+ryCYZLNtVzKmzmWquDoOJZ14oYZwLb0SxIi2V4LQHilaUBydtCEgauHy18DiIO YvXJebPmxxq8F8BOnYM3ggiQhYMLueDuT1Xi1DgrrjD8PQMLIsUOWi4OpCpu7PT9bufF TCsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=VECQAlMEQBzEziMWynewdnnAtoqDKW3dEsYHkkFDRUE=; b=Js7uc72NTwz1OZJqlbMRM+bo4U6UlP8N8iIhj4bI11iU5F9DJySQy1kz/H+ledg0Yi W75vIfTrnIUfKQUEy8T3pDJVDJRnqlM5qDRb1irQbGE21mZV9alwOwAsaHCA7NoHjetW 5xkKcUc1wCiENhW5Pq7CTHRdCvpHEy66vrVIOgP1A/KE5cX+ezeSV5z1elTIyyZP8s1R 3fV8UOuSAIBsfp4fZA6vb776KOhL3GUKTWZjox5PrEVkcow3t5Ez7Wm7/LTvxcS2T/0g phP01XbsFfVDWxysf7IAQgDVFmhxdkoEd5admdDMCN95r9Mtm6Xx49F0wGm0NT2zH/vy ceBg== X-Gm-Message-State: AD7BkJKpVM2jHc5FGNNwrV9ZklLOU0LF5a/NF+XWpthWR4sHSpux6Qqu/y/hh9ThYwSRwIJu0mh+O4r2meXWOQ== X-Received: by 10.107.128.104 with SMTP id b101mr25530704iod.31.1458526075774; Sun, 20 Mar 2016 19:07:55 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105328 On Mon, Mar 21, 2016 at 1:04 PM, BartC wrote: > On 21/03/2016 01:35, Chris Angelico wrote: >> >> On Mon, Mar 21, 2016 at 12:28 PM, Mark Lawrence >> wrote: >>> >>> I got to line 22, saw the bare except, and promptly gave up. >> >> >> Oh, keep going, Mark. It gets better. >> >> def readstrfile(file): >> try: >> data=open(file,"r").read() >> except: >> return 0 >> return data >> >> def start(): >> psource=readstrfile(infile) >> if psource==0: >> print ("Can't open file",infile) >> exit(0) >> >> >> >> So, if any exception happens during the reading of the file, it gets >> squashed, and 0 is returned - which results in a generic message being >> printed, and the program terminating, with return value 0. Awesome! > > > I don't have a clue about exceptions, but why wouldn't read errors be picked > up by the same except: block? They are. So would NameError, AttributeError, KeyboardInterrupt, and anything else that happens to get raised. Everything gets absorbed into the same message, "Can't open file", and then the program exits 0 to make absolutely sure that the caller can't figure anything out. ChrisA