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 b69c4f5 commit b58bcb2
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 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,15 +203,16 @@ 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():
if line.split(): # ie if not empty
try: # empty lines are ignored
fun = int(line.split()[0])
if fun == fun_number:
return 'F' + str(fun) + ' ' + ' '.join(line.split()[1:])
except ValueError:
continue # ignore annotations
with open(os.path.join(os.path.abspath(os.path.split(__file__)[0]),
self.info_filename)) as f:
for line in f.readlines():
if line.split(): # ie if not empty
try: # empty lines are ignored
fun = int(line.split()[0])
if fun == fun_number:
return 'F' + str(fun) + ' ' + ' '.join(line.split()[1:])
except ValueError:
continue # ignore annotations

def instantiate_attributes(self, class_, suffix_list=['target_values', 'targetsOfInterest']):
"""assign ``self.some_attr = class_(self.some_attr)`` if "some_attr" ends with any
Expand Down

0 comments on commit b58bcb2

Please sign in to comment.