Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89618
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.027 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; ';-)': 0.03; 'context': 0.07; 'explicit': 0.07; 'thrown': 0.09; 'cc:addr:python-list': 0.11; 'already,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'unwinds': 0.16; 'subject:python': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'cc:addr:python.org': 0.22; 'skip': 0.24; 'cc:2**0': 0.24; 'header :In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'work.': 0.31; 'code': 0.31; 'concise': 0.31; 'not.': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'done': 0.36; 'manager': 0.38; 'pm,': 0.38; 'even': 0.60; 'skip:o 30': 0.61; 'myself': 0.63; 'more': 0.64; '30,': 0.65; 'here': 0.66; 'close': 0.67; 'honest': 0.78; "'with'": 0.84; '2015': 0.84; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=PFPIh7hk1q6/QeKKKgZJrKhjDxsJ6otZqFDATJr7Y20=; b=yM8rms5Mo7PhAWIjw5kFlGbhsRifOi0IWBWVSiO1dW61uHwMx7ib2TrfnaGXBueiXw j+MClHl2u10Mn2oH8yCyxKFRvROG58sxEa92bgHY2WX+tzn8SkmF/o6Rc62nL7ZzVI/Z uzZVcbbpciND50yYvDk3DGwCFRQg6Pmka1RQ8RXdl4cUsCYtkZFWZeYSaL+oG94UrXcV DykS3qxSg/busO0NWtGMsx1y05mKW6Dm1Oj6WPWDP4E17rI5nDDlDUGplqDIf2K/vj0O 2JT/oA5fRiHz+9IrYpcJgddToe5ssXpCPKhMAQ328jxubNkc1on0BsSX09IrWvcsUIXp QNxw== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.114.35 with SMTP id jd3mr2368871igb.14.1430386750785; Thu, 30 Apr 2015 02:39:10 -0700 (PDT) |
| In-Reply-To | <87twvyvvct.fsf@Equus.decebal.nl> |
| References | <8b2bd328-08a6-4211-85c4-8d117d1aae1e@googlegroups.com> <mailman.107.1430354001.3680.python-list@python.org> <87vbge9lm6.fsf@Equus.decebal.nl> <mailman.118.1430379207.3680.python-list@python.org> <87y4lavy4q.fsf@Equus.decebal.nl> <mailman.120.1430382699.3680.python-list@python.org> <87twvyvvct.fsf@Equus.decebal.nl> |
| Date | Thu, 30 Apr 2015 19:39:10 +1000 |
| Subject | Re: seek operation in python |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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.123.1430387214.3680.python-list@python.org> (permalink) |
| Lines | 18 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1430387214 news.xs4all.nl 2888 [2001:888:2000:d::a6]:42548 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:89618 |
Show key headers only | View raw
On Thu, Apr 30, 2015 at 7:06 PM, Cecil Westerhof <Cecil@decebal.nl> wrote: > I already done it. I thought it not to much work. And it even makes > some code shorter: > - marshal_file = open(expanduser(marshal_filename), 'r') > - not_list = load(marshal_file) > - marshal_file.close() > - return not_list > + with open(expanduser(marshal_filename), 'r') as f: > + return load(f) > > But here I did the close myself already, so that is not completely > honest of me. ;-) The context manager makes your code more concise AND more reliable - an exception thrown by load() will skip the explicit close(), but the 'with' block unwinds correctly whether there's an exception or not. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
seek operation in python siva sankari R <buddingrose11@gmail.com> - 2015-04-29 11:08 -0700
Re: seek operation in python Joel Goldstick <joel.goldstick@gmail.com> - 2015-04-29 14:17 -0400
Re: seek operation in python siva sankari R <buddingrose11@gmail.com> - 2015-04-29 11:26 -0700
Re: seek operation in python Billy Earney <billy.earney@gmail.com> - 2015-04-29 13:42 -0500
Re: seek operation in python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-04-29 21:53 +0100
Re: seek operation in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-30 10:19 +1000
Re: seek operation in python MRAB <python@mrabarnett.plus.com> - 2015-04-29 19:50 +0100
Re: seek operation in python John Gordon <gordon@panix.com> - 2015-04-29 18:53 +0000
Re: seek operation in python Chris Angelico <rosuav@gmail.com> - 2015-04-30 10:33 +1000
Re: seek operation in python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 08:27 +0200
Re: seek operation in python Chris Angelico <rosuav@gmail.com> - 2015-04-30 17:33 +1000
Re: seek operation in python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 10:06 +0200
Re: seek operation in python Dave Angel <davea@davea.name> - 2015-04-30 04:31 -0400
Re: seek operation in python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 11:06 +0200
Re: seek operation in python Chris Angelico <rosuav@gmail.com> - 2015-04-30 19:39 +1000
Re: seek operation in python Larry Hudson <orgnut@yahoo.com> - 2015-04-30 12:38 -0700
Re: seek operation in python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 22:50 +0200
Re: seek operation in python Larry Hudson <orgnut@yahoo.com> - 2015-04-30 19:42 -0700
Re: seek operation in python Cecil Westerhof <Cecil@decebal.nl> - 2015-04-30 14:31 +0200
csiph-web