Skip to content

Commit

Permalink
fix open file not closing in cocopp.testbedsettings
Browse files Browse the repository at this point in the history
  • Loading branch information
nikohansen committed Nov 22, 2023
1 parent f333d2a commit 4664cf3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions code-postprocessing/cocopp/testbedsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def get_first_reference_values():

def get_short_names(file_name):
try:
info_list = open(os.path.join(os.path.dirname(__file__), file_name), 'r').read().split('\n')
with open(os.path.join(os.path.dirname(__file__), file_name), 'r') as f:
info_list = f.read().split('\n')
info_dict = {}
for line in info_list:
if len(line) == 0 or line.startswith('%') or line.isspace():
Expand Down Expand Up @@ -202,8 +203,10 @@ def info(self, fun_number=None):
if fun_number is None:
return self.__doc__

for line in open(os.path.join(os.path.abspath(os.path.split(__file__)[0]),
self.info_filename)).readlines():
with open(os.path.join(os.path.abspath(os.path.split(__file__)[0]),
self.info_filename)) as f:
lines = f.readlines()
for line in lines:
if line.split(): # ie if not empty
try: # empty lines are ignored
fun = int(line.split()[0])
Expand Down

0 comments on commit 4664cf3

Please sign in to comment.