Path: ...!fu-berlin.de!uni-berlin.de!not-for-mail From: Cameron Simpson 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: References: <1ed1c4b0-e89c-4dbc-8b16-35aeebce8ee3@btinternet.com> 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: 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 , Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <1ed1c4b0-e89c-4dbc-8b16-35aeebce8ee3@btinternet.com> Bytes: 3183 On 07Jul2024 22:22, Rob Cliffe 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.