Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #45: virus attack, luser responsible


comp / comp.lang.python / Suggested python feature: allowing except in context maneger

SubjectAuthor
o Suggested python feature: allowing except in context manegerdieter.maurer

1
Subject: Suggested python feature: allowing except in context maneger
From: dieter.maurer@online.de
Newsgroups: comp.lang.python
Date: Thu, 13 Jun 2024 17:44 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: dieter.maurer@online.de
Newsgroups: comp.lang.python
Subject: Suggested python feature: allowing except in context maneger
Date: Thu, 13 Jun 2024 19:44:30 +0200
Lines: 30
Message-ID: <mailman.133.1718307111.2909.python-list@python.org>
References: <CAAtpb8kxWfLVKYW3w3uJRyyQi-3FPxZHYfS2BLe0R6UYSitgZw@mail.gmail.com>
<26219.12286.674908.902341@ixdm.fritz.box>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de WmoaILgkvZYwnQibb7MmKgSFgbwVOXrdTPHW1dlk8yGA==
Cancel-Lock: sha1:nu+KRF9ZcTLVmvcoWjCzBZKW7PY= sha256:DYPKknIyRNDTIlSxHzuiWWyYa7YVJ1x53X8tVUTxrps=
Return-Path: <dieter.maurer@online.de>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=online.de header.i=dieter.maurer@online.de
header.b=fhxmtpfR; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.022
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'subject:python': 0.06;
'received:212.227': 0.07; 'cc:addr:python-list': 0.09;
'received:212.227.126': 0.09; 'skip:` 10': 0.09; 'cc:no real
name:2**0': 0.14; 'dieter': 0.16; 'syntax,': 0.16; 'use:': 0.16;
'cc:addr:python.org': 0.20; 'received:de': 0.23; 'cc:2**0': 0.25;
'suggest': 0.28; 'think': 0.32; 'context': 0.32;
'received:kundenserver.de': 0.32; 'received:mout.kundenserver.de':
0.32; 'requires': 0.34; 'header:In-Reply-To:1': 0.34;
'received:192.168': 0.37; 'use': 0.39; 'wrote': 0.39; 'both':
0.40; 'best': 0.61; 'received:212': 0.62; 'skip:o 20': 0.63;
'your': 0.64; 'manager': 0.68; 'will,': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=online.de;
s=s42582890; t=1718307109; x=1718911909; i=dieter.maurer@online.de;
bh=dUkEip1e1VoWV60V8bgVApxYNqPjbFXcjXa+bjUA0P8=;
h=X-UI-Sender-Class:MIME-Version:Content-Type:
Content-Transfer-Encoding:Message-ID:Date:From:To:Cc:Subject:
In-Reply-To:References:cc:content-transfer-encoding:content-type:
date:from:message-id:mime-version:reply-to:subject:to;
b=fhxmtpfRxm6cxSMjrMYgR6Mn64o6JY3HhGrkPoTR30HVS95TF7XZxBbwPVH/Gs5N
rFFNC5d+9oL5UMCnymVLNd6i+Q5Be4gtT8Jbkl1F35BtVJiULfrYbWYWqdzBqMoX+
TivyfJv8UBTkjO1gWIuNhNCwyIQl8xyhtMg7TmO3FzSq0hD/kWGTreAZtu5/47FJI
9Yt+uejkZJS5TkA00/I5gtIw4JRaXLCBA+4tMreQodycWoxafrUBIJY/B0zjQuT7w
jvEWkKHgiqU8e1YHoE1UxCHWm/iDAK1+MNDbS8ccFR3r3BJ8a8ajKIxTYMsJT6qDD
mTYi8K1+SUP/ULVqQw==
X-UI-Sender-Class: 6003b46c-3fee-4677-9b8b-2b628d989298
In-Reply-To: <CAAtpb8kxWfLVKYW3w3uJRyyQi-3FPxZHYfS2BLe0R6UYSitgZw@mail.gmail.com>
X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid
(x86_64-linux-gnu)
X-Provags-ID: V03:K1:4S4wO8tmxq2Ohx2btpQUk4FNzTO7R1lF2THXExodk3lEhcy6x+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edence: 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: <26219.12286.674908.902341@ixdm.fritz.box>
X-Mailman-Original-References: <CAAtpb8kxWfLVKYW3w3uJRyyQi-3FPxZHYfS2BLe0R6UYSitgZw@mail.gmail.com>
View all headers

Yair Eshel wrote at 2024-6-13 13:01 +0300:
> ...
>I would like to suggest an alternative syntax, that will, in a sense, apply
>the best of both worlds:
>
>import logging
>with open('sample_data/README.md') as f:
> print (len(f.read()))
>except FileNotFoundError:
> logging.error("File not")

Are you aware that in the case of a `FileNotFoundError`
no context manager is created (the context manager is the `f`
in your code).

Why not use:
try:
with open()...
...
except FileNotFoundError:
...

I do not think that your use case requires a `with` extension.

--
Dieter

1

rocksolid light 0.9.8
clearnet tor