@@ -822,34 +822,31 @@ 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
+ for i in range (numpes ):
831
+ files .append (self ._gen_fname ("pe%d.nii" % (i + 1 ), cwd = cwd ))
832
+ break
834
833
return files
835
834
836
835
def _get_numcons (self ):
837
836
numtcons = 0
838
837
numfcons = 0
839
838
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 ()
839
+ with open (self .inputs .tcon_file ) as fp :
840
+ for line in fp :
841
+ if line .startswith ("/NumContrasts" ):
842
+ numtcons = int (line .split ()[- 1 ])
843
+ break
846
844
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 ()
845
+ with open (self .inputs .fcon_file ) as fp :
846
+ for line in fp :
847
+ if line .startswith ("/NumContrasts" ):
848
+ numfcons = int (line .split ()[- 1 ])
849
+ break
853
850
return numtcons , numfcons
854
851
855
852
def _list_outputs (self ):
@@ -1297,19 +1294,17 @@ def _get_numcons(self):
1297
1294
numtcons = 0
1298
1295
numfcons = 0
1299
1296
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 ()
1297
+ with open (self .inputs .tcon_file ) as fp :
1298
+ for line in fp :
1299
+ if line .startswith ("/NumContrasts" ):
1300
+ numtcons = int (line .split ()[- 1 ])
1301
+ break
1306
1302
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 ()
1303
+ with open (self .inputs .fcon_file ) as fp :
1304
+ for line in fp :
1305
+ if line .startswith ("/NumContrasts" ):
1306
+ numfcons = int (line .split ()[- 1 ])
1307
+ break
1313
1308
return numtcons , numfcons
1314
1309
1315
1310
def _list_outputs (self ):
0 commit comments