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 12:35:39 +1100 Lines: 25 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 xcEi9y+nYv32BgXHnj2bOwokyq5OfyFTRujFYkdXBsbA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '21,': 0.07; 'except:': 0.07; 'cc:addr:python-list': 0.09; '22,': 0.09; 'mark.': 0.09; 'oh,': 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; 'try:': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'lawrence': 0.22; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.27; 'print': 0.30; '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; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'skip:p 20': 0.38; 'data': 0.39; 'mark': 0.40; 'subject:The': 0.61; 'mar': 0.65; 'better.': 0.66; 'results': 0.66; 'saw': 0.77; 'chrisa': 0.84; 'promptly': 0.84; '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=E/ANS2390wN9J3AHK96YG0l4qbofkG+/Os41fLDz64k=; b=fdvF6YHBt+2SuhcR7uA5FJB1R4Z3mzp8Gm7LOfaBpesRTyrZw9+c7KgiAx/slsMKsC fuw4g7ZP2Ripm+JMB3/FLrdlYleEjhF9w5oZnM/KENKp1KttQv528wgTzJxvZCsWtRqp 96ZjNzpWAOiZkWrzRA77em3VXImrn71spyXWJWSmgJvj5gN272wFH3GpUILMjvNcY6HN g4YK33kgEC4VTJ4KwgTJl2qvvnbVi7ihy2UeeygEvsTyJ3R+bwkXQ+ptHKeSZGI5FKpZ 2nuCG9uc+19Cc0FaBHJ8Pn3Rc6fKhwhbX03zlXzB9cNso6XZQsAvaUM506VDRcic0Yco FuOg== 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=E/ANS2390wN9J3AHK96YG0l4qbofkG+/Os41fLDz64k=; b=SDYZ3QyMyl3DKLl5WU7TcVr3tmW/zuZByxZ/zzDyasqrcRnD6YeBV3uUYDB/evlMAw ZMz391tJvCaCiU6lcr5GJ1lH23CV5j60n4zRKFJfVgsUV54I1sKDKrbIepkhXL5QacuO 1G/8FK64zM2Htf1ZJYmo9esJz8x9Q7msiE9n8FomXYbGIxCQ8Nv/xE2AWfLEbJ0DwvAX qZP25gwdA3tzfmUsVSQHoyGnC3S/WBJHd5j9uNJWuvOAsfsmeMyTAhoW/YC/BoOZem5m m69b7jV2CPsxXgimcmkcASTKSZPDU8UtK1n3FoWR72wUCzzJgCo6ep7b3Inv4JKmWgLc IdMw== X-Gm-Message-State: AD7BkJLkj9B1LF+S8F7akmJmATAmzo1RLId73eTfIrfZ4fXQXgKEH8U3YcHCX6SFwZP50vibasfiTx2CkgU0Kg== X-Received: by 10.50.23.43 with SMTP id j11mr10479967igf.94.1458524139446; Sun, 20 Mar 2016 18:35:39 -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:105325 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! ChrisA