Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: open() and EOFError Date: Mon, 07 Jul 2014 21:42:25 +0300 Organization: A noiseless patient Spider Lines: 20 Message-ID: <87oax19fji.fsf@elektro.pacujo.net> References: <53ba11fc$0$29985$c3e8da3$5496439d@news.astraweb.com> <53ba538d$0$2926$c3e8da3$76491128@news.astraweb.com> <87wqbp9it2.fsf@elektro.pacujo.net> <53bae1db$0$29995$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx05.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="22353"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7HQAyC0Bkgr5/YhMqTTLn" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:5Ae9FVkp3M9yPgm9lT92S12cniA= sha1:uNU2cZHBPXMtk04oJKykvRKIOk0= Xref: csiph.com comp.lang.python:74132 Steven D'Aprano : > try: > f = open(path) > except Whatever: > handle_error() > else: > with f: > do_stuff() That's cool. Never really used try-else. > That gets old really quickly! But then, handling errors is always the > ugliest part of coding. Hiding the messy details inside a function is > often a good idea. There's no way around it; life is messy. Marko