Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64994
| References | <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> <lcdf0c$bnl$2@ger.gmane.org> <CAPTjJmrOH6_r-qqc1Wcmcud_HV_N-89vZqQpswao59r08u4+Zg@mail.gmail.com> <52EA4F98.2050509@mrabarnett.plus.com> |
|---|---|
| Date | 2014-01-31 00:19 +1100 |
| Subject | Re: Try-except-finally paradox |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.6132.1391087975.18130.python-list@python.org> (permalink) |
On Fri, Jan 31, 2014 at 12:11 AM, MRAB <python@mrabarnett.plus.com> wrote:
> One of the reasons that the 'with' statement was added was to prevent
> the mistake that you've just done. ;-)
>
> What if the file can't be opened?
Yeah, whoops. The open shouldn't be inside try/finally.
def func():
output = open("output.txt", "w")
try:
# do a whole lot of stuff ...
finally:
output.close()
But my point still stands, I believe :)
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Try-except-finally paradox Jessica Ross <deathweasel@gmail.com> - 2014-01-29 21:56 -0800
Re: Try-except-finally paradox Ian Kelly <ian.g.kelly@gmail.com> - 2014-01-29 23:23 -0700
Re: Try-except-finally paradox Andrew Berg <robotsondrugs@gmail.com> - 2014-01-30 00:33 -0600
Re: Try-except-finally paradox Rotwang <sg552@hotmail.co.uk> - 2014-01-30 18:12 +0000
Re: Try-except-finally paradox Ethan Furman <ethan@stoneleaf.us> - 2014-01-30 10:30 -0800
Re: Try-except-finally paradox wxjmfauth@gmail.com - 2014-01-29 22:59 -0800
Re:Try-except-finally paradox Dave Angel <davea@davea.name> - 2014-01-30 07:05 -0500
Re: Try-except-finally paradox Chris Angelico <rosuav@gmail.com> - 2014-01-31 00:02 +1100
Re: Try-except-finally paradox MRAB <python@mrabarnett.plus.com> - 2014-01-30 13:11 +0000
Re: Try-except-finally paradox Chris Angelico <rosuav@gmail.com> - 2014-01-31 00:19 +1100
Re: Try-except-finally paradox Terry Reedy <tjreedy@udel.edu> - 2014-01-31 00:26 -0500
Re: Try-except-finally paradox Göktuğ Kayaalp <self@gkayaalp.com> - 2014-02-01 03:58 +0200
csiph-web