@@ -822,34 +822,31 @@ 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+ for i in range (numpes ):
831+ files .append (self ._gen_fname ("pe%d.nii" % (i + 1 ), cwd = cwd ))
832+ break
834833 return files
835834
836835 def _get_numcons (self ):
837836 numtcons = 0
838837 numfcons = 0
839838 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
846844 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
853850 return numtcons , numfcons
854851
855852 def _list_outputs (self ):
@@ -1297,19 +1294,17 @@ def _get_numcons(self):
12971294 numtcons = 0
12981295 numfcons = 0
12991296 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
13061302 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
13131308 return numtcons , numfcons
13141309
13151310 def _list_outputs (self ):
0 commit comments