@@ -822,34 +822,32 @@ class FILMGLS(FSLCommand):
822822 def _get_pe_files (self , cwd ):
823823 files = None
824824 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
834834 return files
835835
836836 def _get_numcons (self ):
837837 numtcons = 0
838838 numfcons = 0
839839 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
846845 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
853851 return numtcons , numfcons
854852
855853 def _list_outputs (self ):
@@ -1297,19 +1295,17 @@ def _get_numcons(self):
12971295 numtcons = 0
12981296 numfcons = 0
12991297 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
13061303 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
13131309 return numtcons , numfcons
13141310
13151311 def _list_outputs (self ):
0 commit comments