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


Groups > comp.lang.python > #196249 > unrolled thread

Suggested python feature: allowing except in context maneger

Started bydieter.maurer@online.de
First post2024-06-13 19:44 +0200
Last post2024-06-13 19:44 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Suggested python feature: allowing except in context maneger dieter.maurer@online.de - 2024-06-13 19:44 +0200

#196249 — Suggested python feature: allowing except in context maneger

Fromdieter.maurer@online.de
Date2024-06-13 19:44 +0200
SubjectSuggested python feature: allowing except in context maneger
Message-ID<mailman.133.1718307111.2909.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web