Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102996
| Path | csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Terry Reedy <tjreedy@udel.edu> |
| Newsgroups | comp.lang.python |
| Subject | Re: Will file be closed automatically in a "for ... in open..." statement? |
| Date | Tue, 16 Feb 2016 04:41:56 -0500 |
| Lines | 19 |
| Message-ID | <mailman.159.1455615734.22075.python-list@python.org> (permalink) |
| References | <acc702dc-dccd-49ca-857f-b256ad619123@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de cyWAliZJofLVsrgkrgslDw5uWZUOqCHIRTXlW7DDqBIg== |
| 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.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:file': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:a 10': 0.09; 'jan': 0.11; '"with"': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'subject:closed': 0.16; 'wrote:': 0.16; 'do.': 0.22; 'am,': 0.23; 'originally': 0.23; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'books': 0.30; 'file': 0.34; 'received:71': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'to:addr:python.org': 0.40; 'some': 0.40; 'close': 0.61; 'saw': 0.77; 'book:': 0.84; 'received:fios.verizon.net': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | pool-71-185-227-36.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| In-Reply-To | <acc702dc-dccd-49ca-857f-b256ad619123@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21rc2 |
| 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> |
| Xref | csiph.com comp.lang.python:102996 |
Show key headers only | View raw
On 2/16/2016 3:39 AM, jfong@ms4.hinet.net wrote:
> I know
>
> with open('foo.txt') as f:
> ...do something...
>
> will close the file automatically when the "with" block ends.
>
> I also saw codes in a book:
>
> for line in open('foo.txt'):
> ...do something...
Some books were originally written before 'with context_manager' was
added, or a little later, before it became the normal thing to do.
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Will file be closed automatically in a "for ... in open..." statement? jfong@ms4.hinet.net - 2016-02-16 00:39 -0800
Re: Will file be closed automatically in a "for ... in open..." statement? Chris Angelico <rosuav@gmail.com> - 2016-02-16 20:16 +1100
Re: Will file be closed automatically in a "for ... in open..." statement? Cameron Simpson <cs@zip.com.au> - 2016-02-16 20:24 +1100
Re: Will file be closed automatically in a "for ... in open..." statement? Terry Reedy <tjreedy@udel.edu> - 2016-02-16 04:41 -0500
Re: Will file be closed automatically in a "for ... in open..." statement? jfong@ms4.hinet.net - 2016-02-16 20:04 -0800
Re: Will file be closed automatically in a "for ... in open..." statement? Chris Angelico <rosuav@gmail.com> - 2016-02-17 15:36 +1100
Re: Will file be closed automatically in a "for ... in open..." statement? Raspberry Aether <raspberryaether@e-s.invalid> - 2016-02-16 23:42 -0500
Re: Will file be closed automatically in a "for ... in open..." statement? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-02-17 16:51 +1100
Re: Will file be closed automatically in a "for ... in open..." statement? Tim Chase <python.list@tim.thechases.com> - 2016-02-17 20:32 -0600
Re: Will file be closed automatically in a "for ... in open..." statement? jfong@ms4.hinet.net - 2016-02-17 17:29 -0800
Re: Will file be closed automatically in a "for ... in open..." statement? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-02-18 02:05 +0000
Re: Will file be closed automatically in a "for ... in open..." statement? Jeremy Leonard <jrmy.lnrd@gmail.com> - 2016-02-18 10:02 -0800
csiph-web