@@ -822,34 +822,32 @@ class FILMGLS(FSLCommand):
822
822
def _get_pe_files (self , cwd ):
823
823
files = None
824
824
if isdefined (self .inputs .design_file ):
825
- fp = open (self .inputs .design_file )
826
- for line in fp . readlines () :
827
- if line .startswith ("/NumWaves" ):
828
- numpes = int (line .split ()[- 1 ])
829
- files = []
830
- for i in range ( numpes ):
831
- files . append ( self . _gen_fname ( "pe%d.nii" % ( i + 1 ), cwd = cwd ) )
832
- break
833
- fp . close ()
825
+ with open (self .inputs .design_file ) as fp :
826
+ for line in fp :
827
+ if line .startswith ("/NumWaves" ):
828
+ numpes = int (line .split ()[- 1 ])
829
+ files = [
830
+ self . _gen_fname ( f"pe { i + 1 } .nii" , cwd = cwd )
831
+ for i in range ( numpes )
832
+ ]
833
+ break
834
834
return files
835
835
836
836
def _get_numcons (self ):
837
837
numtcons = 0
838
838
numfcons = 0
839
839
if isdefined (self .inputs .tcon_file ):
840
- fp = open (self .inputs .tcon_file )
841
- for line in fp .readlines ():
842
- if line .startswith ("/NumContrasts" ):
843
- numtcons = int (line .split ()[- 1 ])
844
- break
845
- fp .close ()
840
+ with open (self .inputs .tcon_file ) as fp :
841
+ for line in fp :
842
+ if line .startswith ("/NumContrasts" ):
843
+ numtcons = int (line .split ()[- 1 ])
844
+ break
846
845
if isdefined (self .inputs .fcon_file ):
847
- fp = open (self .inputs .fcon_file )
848
- for line in fp .readlines ():
849
- if line .startswith ("/NumContrasts" ):
850
- numfcons = int (line .split ()[- 1 ])
851
- break
852
- fp .close ()
846
+ with open (self .inputs .fcon_file ) as fp :
847
+ for line in fp :
848
+ if line .startswith ("/NumContrasts" ):
849
+ numfcons = int (line .split ()[- 1 ])
850
+ break
853
851
return numtcons , numfcons
854
852
855
853
def _list_outputs (self ):
@@ -1297,19 +1295,17 @@ def _get_numcons(self):
1297
1295
numtcons = 0
1298
1296
numfcons = 0
1299
1297
if isdefined (self .inputs .tcon_file ):
1300
- fp = open (self .inputs .tcon_file )
1301
- for line in fp .readlines ():
1302
- if line .startswith ("/NumContrasts" ):
1303
- numtcons = int (line .split ()[- 1 ])
1304
- break
1305
- fp .close ()
1298
+ with open (self .inputs .tcon_file ) as fp :
1299
+ for line in fp :
1300
+ if line .startswith ("/NumContrasts" ):
1301
+ numtcons = int (line .split ()[- 1 ])
1302
+ break
1306
1303
if isdefined (self .inputs .fcon_file ):
1307
- fp = open (self .inputs .fcon_file )
1308
- for line in fp .readlines ():
1309
- if line .startswith ("/NumContrasts" ):
1310
- numfcons = int (line .split ()[- 1 ])
1311
- break
1312
- fp .close ()
1304
+ with open (self .inputs .fcon_file ) as fp :
1305
+ for line in fp :
1306
+ if line .startswith ("/NumContrasts" ):
1307
+ numfcons = int (line .split ()[- 1 ])
1308
+ break
1313
1309
return numtcons , numfcons
1314
1310
1315
1311
def _list_outputs (self ):
0 commit comments