diff --git a/code-postprocessing/cocopp/testbedsettings.py b/code-postprocessing/cocopp/testbedsettings.py index e97a66c79..a17173523 100644 --- a/code-postprocessing/cocopp/testbedsettings.py +++ b/code-postprocessing/cocopp/testbedsettings.py @@ -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(): @@ -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