summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Scherer <andreas_tex@freenet.de>2024-06-28 21:47:10 +0000
committerAndreas Scherer <andreas_tex@freenet.de>2024-06-28 21:47:10 +0000
commitcd09ce29745ba3b8073b18dc4eb76defaa91acf1 (patch)
tree388a945ed7d4dc134c42232ff340c5cfb8b4b1e1
parent0981181c3ed30cac5821dffe5bbcabdef0e91698 (diff)
Merge 'with' and 'try..except'.
No need to store the file handles in 'self'. git-svn-id: svn://tug.org/texlive/trunk@71644 c570f23f-e606-0410-a88d-b1316a301751
-rwxr-xr-xBuild/source/texk/web2c/tests/fix-changefile-lines.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/Build/source/texk/web2c/tests/fix-changefile-lines.py b/Build/source/texk/web2c/tests/fix-changefile-lines.py
index 6e2e2a6de4b..ca07ced1a91 100755
--- a/Build/source/texk/web2c/tests/fix-changefile-lines.py
+++ b/Build/source/texk/web2c/tests/fix-changefile-lines.py
@@ -50,13 +50,12 @@ class WebReader:
self.part_cnt = 0
self.section_cnt = 0
try:
- self._web_file = open(web_file, "r")
+ with open(web_file, "r") as file:
+ self._web_lines = [line.rstrip() for line in file]
except OSError:
eprint(f"Could not open {web_file}")
print(USAGE)
sys.exit(1)
- with self._web_file:
- self._web_lines = [line.rstrip() for line in self._web_file]
def next_line(self):
"""Returns the triple of current part, section and line numbers, as
@@ -105,13 +104,12 @@ class ChangeReader:
self._chunk_start = None
self._match_lines = None
try:
- self._change_file = open(change_file, "r")
+ with open(change_file, "r") as file:
+ self._lines = [line.rstrip() for line in file]
except OSError:
eprint(f"Could not open {change_file}")
print(USAGE)
sys.exit(1)
- with self._change_file:
- self._lines = [line.rstrip() for line in self._change_file]
def advance_to_next_chunk(self):
"""Find the next change chunk. Store where it starts and