Skip to content

Commit 568275e

Browse files
committed
Close file when reading number of interactions.
1 parent dd7909e commit 568275e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

axelrod/interaction_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def read_interactions_from_file(filename, progress_bar=True,
112112
"""
113113
if progress_bar:
114114
if not num_interactions:
115-
num_interactions = sum(1 for line in open(filename))
115+
with open(filename) as f:
116+
num_interactions = sum(1 for line in f)
116117
progress_bar = tqdm.tqdm(total=num_interactions, desc="Loading")
117118

118119
pairs_to_interactions = {}

axelrod/result_set.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,8 @@ def create_progress_bar(self, desc=None):
765765
A description.
766766
"""
767767
if not self.num_interactions:
768-
self.num_interactions = sum(1 for line in open(self.filename))
768+
with open(self.filename) as f:
769+
self.num_interactions = sum(1 for line in f)
769770
return tqdm.tqdm(total=self.num_interactions, desc=desc)
770771

771772
def _read_players_and_repetition_numbers(self, progress_bar=False):

0 commit comments

Comments
 (0)