Re: Best use of "open" context manager

Liste des GroupesRevenir à cl python 
Sujet : Re: Best use of "open" context manager
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.python
Date : 12. Jul 2024, 13:55:13
Autres entêtes
Organisation : Stefan Ram
Message-ID : <code-20240712125444@ram.dialup.fu-berlin.de>
References : 1 2 3
Albert-Jan Roskam <sjeik_appie@hotmail.com> schrieb oder zitierte:
Or like below, although pylint complains about this: "consider using
with". Less indentation this way.

f = None
try:
   f = open(FILENAME)
   records = f.readlines()

  This try clause would also catch exception raised by the readlines
  call, and I thought that this was what the OP was looking to avoid.

except Exception:
   sys.exit(1)

  When this code is part of a library, it might not be appropriate
  to make the whole application exit at this point.

Date Sujet#  Auteur
12 Jul 24 * Re: Best use of "open" context manager2Albert-Jan Roskam
12 Jul 24 `- Re: Best use of "open" context manager1Stefan Ram

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal