Skip to content

Commit

Permalink
open/close files with context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Jul 28, 2023
1 parent ab49ede commit 9cb3c8a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions brian2genn/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,8 @@ def run(self, directory, use_GPU, with_output):
check_call(["./main", "test", str(self.run_duration)],
cwd=directory)
self.has_been_run = True
last_run_info = open(
os.path.join(directory, 'results/last_run_info.txt')).read()
with open(os.path.join(directory, 'results/last_run_info.txt')) as f:
last_run_info = f.read()
self._last_run_time, self._last_run_completed_fraction = map(float,
last_run_info.split())

Expand Down Expand Up @@ -1821,16 +1821,17 @@ def generate_makefile(self, directory, use_GPU):
if os.sys.platform == 'win32':
project_tmp = GeNNCodeObject.templater.project_vcxproj(None, None,
source_files=self.source_files)
open(os.path.join(directory, 'project.vcxproj'), 'w').write(
project_tmp)
with open(os.path.join(directory, 'project.vcxproj'), 'w') as f:
f.write(project_tmp)
else:
compile_args_gcc = get_gcc_compile_args()
linker_flags = ' '.join(prefs.codegen.cpp.extra_link_args)
makefile_tmp = GeNNCodeObject.templater.Makefile(None, None,
source_files=self.source_files,
compiler_flags=compile_args_gcc,
linker_flags=linker_flags)
open(os.path.join(directory, 'Makefile'), 'w').write(makefile_tmp)
with open(os.path.join(directory, 'Makefile'), 'w') as f:
f.write(makefile_tmp)

def generate_objects_source(self, arange_arrays, net, static_array_specs,
synapses, writer):
Expand Down

0 comments on commit 9cb3c8a

Please sign in to comment.