Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #196411

Re: Best use of "open" context manager

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Cameron Simpson <cs@cskk.id.au>
Newsgroups comp.lang.python
Subject Re: Best use of "open" context manager
Date Mon, 8 Jul 2024 12:45:21 +1000
Lines 7
Message-ID <mailman.19.1720406738.2981.python-list@python.org> (permalink)
References <1ed1c4b0-e89c-4dbc-8b16-35aeebce8ee3@btinternet.com> <ZotSwXK2ajuqmWHq@cskk.homeip.net>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.uni-berlin.de TofJvvtkGeB349rP56bMmQNV8jL8pVBus7lUEJPW2buA==
Cancel-Lock sha1:3bUzfAXMNKpFepWWaHkCclfWc4Y= sha256:7yxgqLJj54EwIzRrjTkbUinWVTxQauX3wW7drz6teKQ=
Return-Path <cameron@cskk.id.au>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
Authentication-Results mail.python.org; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'this:': 0.03; 'cc:addr :python-list': 0.09; 'valueerror:': 0.09; '22:22,': 0.16; 'cc:name:python': 0.16; 'closes': 0.16; 'from:addr:cs': 0.16; 'from:addr:cskk.id.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:13.237': 0.16; 'received:13.237.201': 0.16; 'received:13.237.201.189': 0.16; 'received:cskk.id.au': 0.16; 'received:id.au': 0.16; 'received:mail.cskk.id.au': 0.16; 'wrote:': 0.16; 'cc:addr:python.org': 0.20; 'closed': 0.22; 'version': 0.23; 'cc:2**0': 0.25; 'header:User-Agent:1': 0.30; "doesn't": 0.32; 'course.': 0.32; 'but': 0.32; 'same': 0.34; 'header:In-Reply- To:1': 0.34; 'received:au': 0.35; 'runs': 0.35; 'file': 0.38; 'received:13': 0.64; 'received:userid': 0.66; 'rob': 0.84; 'subject:manager': 0.84; 'subject:open': 0.84; 'legal,': 0.93
Mail-Followup-To Rob Cliffe <rob.cliffe@btinternet.com>, Python <python-list@python.org>
Content-Disposition inline
In-Reply-To <1ed1c4b0-e89c-4dbc-8b16-35aeebce8ee3@btinternet.com>
User-Agent Mutt/2.2.13 (2024-03-09)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.39
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 <https://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>
X-Mailman-Original-Message-ID <ZotSwXK2ajuqmWHq@cskk.homeip.net>
X-Mailman-Original-References <1ed1c4b0-e89c-4dbc-8b16-35aeebce8ee3@btinternet.com>
Xref csiph.com comp.lang.python:196411

Show key headers only | View raw


On 07Jul2024 22:22, Rob Cliffe <rob.cliffe@btinternet.com> wrote:
>it's legal, but doesn't work (trying to access the file after "with f" 
>raises the same
>    ValueError: I/O operation on closed file.

Just to this: of course. The with closes the file. But my version runs 
the with after the try/except.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Best use of "open" context manager Cameron Simpson <cs@cskk.id.au> - 2024-07-08 12:45 +1000

csiph-web