@@ -142,13 +142,12 @@ class Level1Design(BaseInterface):
142
142
output_spec = Level1DesignOutputSpec
143
143
144
144
def _create_ev_file (self , evfname , evinfo ):
145
- f = open (evfname , "w" )
146
- for i in evinfo :
147
- if len (i ) == 3 :
148
- f .write (f"{ i [0 ]:f} { i [1 ]:f} { i [2 ]:f} \n " )
149
- else :
150
- f .write ("%f\n " % i [0 ])
151
- f .close ()
145
+ with open (evfname , "w" ) as f :
146
+ for i in evinfo :
147
+ if len (i ) == 3 :
148
+ f .write (f"{ i [0 ]:f} { i [1 ]:f} { i [2 ]:f} \n " )
149
+ else :
150
+ f .write ("%f\n " % i [0 ])
152
151
153
152
def _create_ev_files (
154
153
self ,
@@ -319,7 +318,7 @@ def _create_ev_files(
319
318
320
319
for fconidx in ftest_idx :
321
320
fval = 0
322
- if con [0 ] in con_map . keys () and fconidx in con_map [con [0 ]]:
321
+ if con [0 ] in con_map and fconidx in con_map [con [0 ]]:
323
322
fval = 1
324
323
ev_txt += contrast_ftest_element .substitute (
325
324
cnum = ftest_idx .index (fconidx ) + 1 ,
@@ -403,9 +402,8 @@ def _run_interface(self, runtime):
403
402
fsf_txt += cond_txt
404
403
fsf_txt += fsf_postscript .substitute (overwrite = 1 )
405
404
406
- f = open (os .path .join (cwd , "run%d.fsf" % i ), "w" )
407
- f .write (fsf_txt )
408
- f .close ()
405
+ with open (os .path .join (cwd , "run%d.fsf" % i ), "w" ) as f :
406
+ f .write (fsf_txt )
409
407
410
408
return runtime
411
409
@@ -946,9 +944,8 @@ def _run_interface(self, runtime):
946
944
for i , rundir in enumerate (ensure_list (self .inputs .feat_dirs )):
947
945
fsf_txt += fsf_dirs .substitute (runno = i + 1 , rundir = os .path .abspath (rundir ))
948
946
fsf_txt += fsf_footer .substitute ()
949
- f = open (os .path .join (os .getcwd (), "register.fsf" ), "w" )
950
- f .write (fsf_txt )
951
- f .close ()
947
+ with open (os .path .join (os .getcwd (), "register.fsf" ), "w" ) as f :
948
+ f .write (fsf_txt )
952
949
953
950
return runtime
954
951
@@ -1414,9 +1411,8 @@ def _run_interface(self, runtime):
1414
1411
1415
1412
# write design files
1416
1413
for i , name in enumerate (["design.mat" , "design.con" , "design.grp" ]):
1417
- f = open (os .path .join (cwd , name ), "w" )
1418
- f .write (txt [name ])
1419
- f .close ()
1414
+ with open (os .path .join (cwd , name ), "w" ) as f :
1415
+ f .write (txt [name ])
1420
1416
1421
1417
return runtime
1422
1418
@@ -1583,9 +1579,8 @@ def _run_interface(self, runtime):
1583
1579
if ("fts" in key ) and (nfcons == 0 ):
1584
1580
continue
1585
1581
filename = key .replace ("_" , "." )
1586
- f = open (os .path .join (cwd , filename ), "w" )
1587
- f .write (val )
1588
- f .close ()
1582
+ with open (os .path .join (cwd , filename ), "w" ) as f :
1583
+ f .write (val )
1589
1584
1590
1585
return runtime
1591
1586
0 commit comments