Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74167
| From | "Neil D. Cerutti" <neilc@norwich.edu> |
|---|---|
| Subject | Re: open() and EOFError |
| Date | 2014-07-08 10:29 -0400 |
| References | (3 earlier) <CAPTjJmos00xjJVMZFKY1F9Z8L+ByusHD-ciuats5FYbwQ6RF+g@mail.gmail.com> <mailman.11603.1404753981.18130.python-list@python.org> <87wqbp9it2.fsf@elektro.pacujo.net> <c20k45Fijs1U1@mid.individual.net> <lpf9ca$jgm$1@ger.gmane.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11625.1404829781.18130.python-list@python.org> (permalink) |
On 7/7/2014 7:10 PM, Mark Lawrence wrote: > 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. On Windows it's my experience that EOF from interactive sessions is ignored. Programs keep going as best they can, providing some other means of exit, e.g., an 'exit' command. But maybe that's just the shell. -- Neil Cerutti
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
open() and EOFError Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-07 03:20 +0000
Re: open() and EOFError Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-07-07 17:04 +1200
Re: open() and EOFError Steven D'Aprano <steve@pearwood.info> - 2014-07-07 08:00 +0000
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-07 18:09 +1000
Re: open() and EOFError Dave Angel <davea@davea.name> - 2014-07-07 08:14 -0400
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-07 22:19 +1000
Re: open() and EOFError Roy Smith <roy@panix.com> - 2014-07-07 08:46 -0400
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-07 22:58 +1000
Re: open() and EOFError Roy Smith <roy@panix.com> - 2014-07-07 20:26 -0400
Re: open() and EOFError Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-07-08 09:50 +1200
Re: open() and EOFError Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-07 15:45 +0000
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-08 01:53 +1000
Re: open() and EOFError Marko Rauhamaa <marko@pacujo.net> - 2014-07-07 19:08 +0300
Re: open() and EOFError Marko Rauhamaa <marko@pacujo.net> - 2014-07-07 19:12 +0300
Re: open() and EOFError Roy Smith <roy@panix.com> - 2014-07-07 08:39 -0400
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-07 22:55 +1000
Re: open() and EOFError Roy Smith <roy@panix.com> - 2014-07-07 20:28 -0400
Re: open() and EOFError Terry Reedy <tjreedy@udel.edu> - 2014-07-07 14:49 -0400
Re: open() and EOFError Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-07-08 10:04 +1200
Re: open() and EOFError Grant Edwards <invalid@invalid.invalid> - 2014-07-08 14:19 +0000
Re: open() and EOFError Terry Reedy <tjreedy@udel.edu> - 2014-07-08 11:08 -0400
Re: open() and EOFError Tim Chase <python.list@tim.thechases.com> - 2014-07-08 10:20 -0500
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-09 01:24 +1000
Re: open() and EOFError Tim Chase <python.list@tim.thechases.com> - 2014-07-08 10:46 -0500
Re: open() and EOFError Roy Smith <roy@panix.com> - 2014-07-08 21:05 -0400
Re: open() and EOFError Anssi Saari <as@sci.fi> - 2014-07-10 22:40 +0300
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-09 01:49 +1000
Re: ^D vs ^Z as EOF and DOS dinosaurs talking (was: open() and EOFError) Tim Chase <python.list@tim.thechases.com> - 2014-07-08 10:57 -0500
Re: ^D vs ^Z as EOF and DOS dinosaurs talking (was: open() and EOFError) Jan van den Broek <balglaas@xs4all.nl> - 2014-07-08 16:38 +0000
Re: ^D vs ^Z as EOF and DOS dinosaurs talking (was: open() and EOFError) Chris Angelico <rosuav@gmail.com> - 2014-07-09 02:20 +1000
Re: open() and EOFError Tim Chase <python.list@tim.thechases.com> - 2014-07-08 11:40 -0500
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-09 02:50 +1000
Re: open() and EOFError Steven D'Aprano <steve@pearwood.info> - 2014-07-08 09:03 +0000
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-08 20:29 +1000
Re: open() and EOFError Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-07 14:06 +0100
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-07 23:27 +1000
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-07 23:29 +1000
Re: open() and EOFError Dan Stromberg <drsalists@gmail.com> - 2014-07-07 09:07 -0700
Re: open() and EOFError Ian Kelly <ian.g.kelly@gmail.com> - 2014-07-07 11:25 -0600
Re: open() and EOFError Marko Rauhamaa <marko@pacujo.net> - 2014-07-07 20:31 +0300
Re: open() and EOFError Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-07-07 18:07 +0000
Re: open() and EOFError Marko Rauhamaa <marko@pacujo.net> - 2014-07-07 21:42 +0300
Re: open() and EOFError Roy Smith <roy@panix.com> - 2014-07-07 20:22 -0400
Re: open() and EOFError Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-07-08 10:09 +1200
Re: open() and EOFError Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-07-08 00:10 +0100
Re: open() and EOFError "Neil D. Cerutti" <neilc@norwich.edu> - 2014-07-08 10:29 -0400
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-08 03:29 +1000
Re: open() and EOFError Marko Rauhamaa <marko@pacujo.net> - 2014-07-07 20:40 +0300
Re: open() and EOFError Chris Angelico <rosuav@gmail.com> - 2014-07-08 10:55 +1000
Re: open() and EOFError Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-07-07 18:54 -0400
csiph-web