Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: open() and EOFError Date: Tue, 08 Jul 2014 10:09:07 +1200 Lines: 19 Message-ID: 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-Trace: individual.net DopDOd8KZCNDH/0iAcFw/gELODzCYWrXwV6ew1aZSOBtlodraQ Cancel-Lock: sha1:QDjCRtXFIf8AAZdDOBP7yXjrfec= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: <87wqbp9it2.fsf@elektro.pacujo.net> Xref: csiph.com comp.lang.python:74139 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. -- Greg