On 13 Jun 2024, at 11:01, Yair Eshel via Python-list <[email protected]> wrote:
I read this is a good place to give some suggestions for features in
python.
...
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")
```
try:
with open()...
...
except FileNotFoundError:
...
```
Cameron, I'm not really sure I got your point. I've used the "file not
found" exception as an example for a behavior typical on context managers. >This could be a failure to connect to DB, or threads. It also applies to
any kind of possible exception, whether cased by the context manager itself >or the lines inside it. Long story short, this syntax change is as useful
as context managers are
On 13Jun2024 19:44, [email protected] <[email protected]>
wrote:
Why not use:
```
try:
with open()...
...
except FileNotFoundError:
...
```
This is exactly what the OP was expressing dissatisfaction with.
I'm -1 on the idea myself - not every combination of things needs
additional syntactic support, and doing stuff like merging an `except`
with a `wtih` is bound to introduce some weird corner case,
complicating its semantics.
Cheers,
Cameron Simpson <[email protected]>
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 741 |
| Nodes: | 16 (2 / 14) |
| Uptime: | 59:14:39 |
| Calls: | 12,446 |
| Calls today: | 1 |
| Files: | 15,192 |
| Messages: | 6,537,424 |