Path: csiph.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Mark Lawrence 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 02:02:13 +0000 Lines: 42 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=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de W7Dtgro0UDckEfYpFs/4BwF32ApZ9fHN4/HRlEgUPAOg== 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; 'from:addr:yahoo.co.uk': 0.05; '21,': 0.07; 'except:': 0.07; '22,': 0.09; 'mark.': 0.09; 'oh,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:which': 0.09; 'exception': 0.13; 'def': 0.13; 'file,': 0.15; '2016': 0.16; 'cares': 0.16; 'pythonic': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'rogue': 0.16; 'subject:?)': 0.16; 'wrote:': 0.16; 'later': 0.16; 'try:': 0.18; 'language': 0.19; 'essential': 0.20; 'lawrence': 0.22; 'trying': 0.22; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'chris': 0.26; 'question': 0.27; 'data,': 0.27; 'revert': 0.27; 'print': 0.30; 'code': 0.30; "can't": 0.32; 'up.': 0.32; 'language.': 0.32; 'returned': 0.32; 'open': 0.33; "i'll": 0.33; 'file': 0.34; 'skip:d 20': 0.34; 'gets': 0.35; 'so,': 0.35; 'false': 0.35; 'generic': 0.35; 'but': 0.36; 'to:addr:python- list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'received:org': 0.37; 'skip:p 20': 0.38; 'data': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'some': 0.40; 'your': 0.60; 'subject:The': 0.61; 'details': 0.62; 'charset:windows-1252': 0.62; 'more': 0.63; 'our': 0.64; 'mar': 0.65; 'today': 0.65; 'better.': 0.66; 'results': 0.66; 'teach': 0.70; 'saw': 0.77; 'chrisa': 0.84; 'cpu.': 0.84; 'killing': 0.84; 'powerful,': 0.84; 'promptly': 0.84; 'pythonistas,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 80.234.129.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 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:105326 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! > > ChrisA > The essential question is "which is faster?". Who cares about trivial little details like the user being given false data, as (say) they can open the file but can't read it. Or inadvertantly writing an infinite loop and not being able to CTRL-C out of it, having to revert to your OS to kill the rogue that's killing your CPU. 25 years of trying to teach people how to write Pythonic code and this is how far we've got. Heck, I think I'll see my GP later today for some more, more powerful, tranquilisers. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence