Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '(at': 0.04; 'from:addr:yahoo.co.uk': 0.04; 'lawrence': 0.09; 'pep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'language.': 0.14; 'cleaner': 0.16; 'finer': 0.16; 'guarded': 0.16; 'ioerror:': 0.16; 'open()': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'language': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'bit': 0.19; 'header:User-Agent:1': 0.23; '---': 0.24; 'handling': 0.26; 'least': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'usually': 0.31; 'exceptions': 0.31; 'file': 0.32; 'another': 0.32; 'maybe': 0.34; 'could': 0.34; 'except': 0.35; 'revert': 0.36; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'free': 0.61; 'viruses': 0.61; 'protection': 0.63; 'our': 0.64; 'within': 0.65; 'antivirus': 0.68; 'home.': 0.72 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: open() and EOFError Date: Tue, 08 Jul 2014 00:10:45 +0100 References: <53ba11fc$0$29985$c3e8da3$5496439d@news.astraweb.com> <53ba538d$0$2926$c3e8da3$76491128@news.astraweb.com> <87wqbp9it2.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-92-18-5-57.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: X-Antivirus: avast! (VPS 140707-1, 07/07/2014), Outbound message X-Antivirus-Status: Clean 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404774617 news.xs4all.nl 2895 [2001:888:2000:d::a6]:53951 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:74141 On 07/07/2014 23:09, Gregory Ewing wrote: > Marko Rauhamaa wrote: >> with open(path) as f: >> ... >> >> If the open() call is guarded against exceptions (as it usually should), >> one must revert to the classic syntax: > > Hmmm, maybe we could do with a with-except statement: > > with open(path) as f: > ... > except IOError: > # Catches exceptions in the with-expression only > ... > > Although that would be a bit confusing. > I wrap the with inside a try/except, the other file handling parts within another try/except and use the finer grained exceptions from PEP 3151 to write (at least to my eye) cleaner looking code. Somehow I think we'll get agreement on the best way to do this when the cows come home. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.com