Or like below, although pylint complains about this: "consider using
with". Less indentation this way.
f = None
try:
f = open(FILENAME)
records = f.readlines()
except Exception:
sys.exit(1)
finally:
if f is not None:
f.close()
--
https://mail.python.org/mailman/listinfo/python-list
Re: Best use of "open" context manager
Albert-Jan Roskam via Python-list Fri, 12 Jul 2024 02:33:58 -0700
- Re: Best use of "open" context... Alan Gauld via Python-list
- Re: Best use of "open" context... Oscar Benjamin via Python-list
- Re: Best use of "open" co... Rob Cliffe via Python-list
- Re: Best use of "open" context... Thomas Passin via Python-list
- Re: Best use of "open" context... Richard Damon via Python-list
- Re: Best use of "open" context... dn via Python-list
- Re: Best use of "open" context... Cameron Simpson via Python-list
- Re: Best use of "open" co... Rob Cliffe via Python-list
- Re: Best use of "open"... Cameron Simpson via Python-list
- Re: Best use of "open"... Cameron Simpson via Python-list
- Re: Best use of "open&... Albert-Jan Roskam via Python-list
