Suggested python feature: allowing except in context maneger
dieter.maurer at online.de
dieter.maurer at online.de
Thu Jun 13 13:44:30 EDT 2024
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
More information about the Python-list
mailing list