Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #74098
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| 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; 'else:': 0.03; 'raises': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'try:': 0.09; 'windows,': 0.09; 'wrote': 0.14; '(before': 0.16; 'ioerror:': 0.16; 'merely': 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'thought.': 0.16; 'exception': 0.16; 'so.': 0.16; 'wrote:': 0.18; 'first.': 0.19; 'thanks.': 0.20; '>>>': 0.22; 'this?': 0.23; 'instead.': 0.24; 'visible': 0.24; 'mon,': 0.24; 'second': 0.26; 'header:X -Complaints-To:1': 0.27; 'leave': 0.29; 'raise': 0.29; 'code': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'maintaining': 0.32; 'except': 0.35; 'there': 0.35; 'next': 0.36; 'example,': 0.37; 'depends': 0.38; 'to:addr:python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'you.': 0.62; 'name': 0.63; 'jul': 0.74; 'obvious': 0.74; 'glance': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Dave Angel <davea@davea.name> |
| Subject | Re: open() and EOFError |
| Date | Mon, 7 Jul 2014 08:14:31 -0400 (EDT) |
| Organization | news.gmane.org |
| References | <53ba11fc$0$29985$c3e8da3$5496439d@news.astraweb.com> <c1uo2eF60gfU1@mid.individual.net> <53ba538d$0$2926$c3e8da3$76491128@news.astraweb.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | 97.73.240.18 |
| X-Newsreader | PiaoHong.Usenet.Client.VIP:1.56 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11586.1404735158.18130.python-list@python.org> (permalink) |
| Lines | 37 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1404735158 news.xs4all.nl 2889 [2001:888:2000:d::a6]:48451 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:74098 |
Show key headers only | View raw
Steven D'Aprano <steve@pearwood.info> Wrote in message:
> On Mon, 07 Jul 2014 17:04:12 +1200, Gregory Ewing wrote:
>
>> Steven D'Aprano wrote:
>>> Are there any circumstances where merely *opening* a file (before
>>> reading it) can raise EOFError?
>>
>> I don't think so. As far as I know, the only built-in thing that raises
>> EOFError is input() (and raw_input() in Py2).
>
> Thanks. That's what I thought.
>
> How do people feel about code like this?
>
> try:
> name = input("Enter file name, or Ctrl-D to exit")
> # On Windows, use Ctrl-Z [enter] instead.
> fp = open(name)
> except EOFError:
> sys.exit()
> except IOError:
> handle_bad_file(name)
> else:
> handle_good_file(fp)
>
Depends on who is going to be maintaining your code next year.Be
sure and leave him some comments. Even if it's going to be you.
For example, it's not obvious at a glance that name is visible in
the second exception block and not the first.
--
DaveA
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