@@ -85,9 +85,8 @@ def data_aggregation(): # all data from all the files is collected
85
85
86
86
print ("Your command was: " + command )
87
87
if o is not None :
88
- f = open (o , "w" )
89
- f .write ("Your command was " + command )
90
- f .close ()
88
+ with open (o , "w" ) as f :
89
+ f .write ("Your command was " + command )
91
90
verbosity = 0
92
91
restParser = RestParser (verbosity_level = int (verbosity ))
93
92
restParser .setOutputFormat (RestParser .OBJECT_FORMAT )
@@ -149,9 +148,11 @@ def data_aggregation(): # all data from all the files is collected
149
148
) as temp : # turns the dataframe into a temporary csv
150
149
df .to_csv (temp .name + ".csv" )
151
150
temp .close ()
152
- data = list (
153
- csv .reader (open (temp .name + ".csv" ))
154
- ) # makes the csv a 2D list to make it easier to call the contents of certain cells
151
+
152
+ with open (temp .name + ".csv" ) as fp :
153
+ data = list (
154
+ csv .reader (fp )
155
+ ) # makes the csv a 2D list to make it easier to call the contents of certain cells
155
156
156
157
var_list = variables .split ("," ) # makes a list of the independent variables
157
158
numcols = (len (data ) - 1 ) // (
@@ -293,20 +294,18 @@ def data_aggregation(): # all data from all the files is collected
293
294
+ ". The model cannot run because this will skew the data. Try checking your spelling or use nidm_query.py to see other possible variables."
294
295
)
295
296
if o is not None :
296
- f = open (o , "a" )
297
- f .write ("Your variables were " + v )
298
- f .write (
299
- "The following variables were not found in "
300
- + nidm_file
301
- + ". The model cannot run because this will skew the data. Try checking your spelling or use nidm_query.py to see other possible variables."
302
- )
303
- f .close ()
297
+ with open (o , "a" ) as f :
298
+ f .write ("Your variables were " + v )
299
+ f .write (
300
+ "The following variables were not found in "
301
+ + nidm_file
302
+ + ". The model cannot run because this will skew the data. Try checking your spelling or use nidm_query.py to see other possible variables."
303
+ )
304
304
for i in range (0 , len (not_found_list )):
305
305
print (str (i + 1 ) + ". " + not_found_list [i ])
306
306
if o is not None :
307
- f = open (o , "a" )
308
- f .write (str (i + 1 ) + ". " + not_found_list [i ])
309
- f .close ()
307
+ with open (o , "a" ) as f :
308
+ f .write (str (i + 1 ) + ". " + not_found_list [i ])
310
309
for j in range (len (not_found_list ) - 1 , 0 , - 1 ):
311
310
not_found_list .pop (j )
312
311
not_found_count = not_found_count + 1
@@ -388,13 +387,12 @@ def dataparsing(): # The data is changed to a format that is usable by the line
388
387
)
389
388
print ()
390
389
if o is not None :
391
- f = open (o , "a" )
392
- f .write (df_final .to_string (header = True , index = True ))
393
- f .write (
394
- "\n \n ***********************************************************************************************************"
395
- )
396
- f .write ("\n \n Model Results: " )
397
- f .close ()
390
+ with open (o , "a" ) as f :
391
+ f .write (df_final .to_string (header = True , index = True ))
392
+ f .write (
393
+ "\n \n ***********************************************************************************************************"
394
+ )
395
+ f .write ("\n \n Model Results: " )
398
396
399
397
400
398
def cluster_number ():
@@ -562,8 +560,8 @@ def cluster_number():
562
560
plt .show ()
563
561
564
562
if o is not None :
565
- f = open (o , "a" )
566
- f . close ()
563
+ with open (o , "a" ):
564
+ pass
567
565
568
566
569
567
def opencsv (data ):
0 commit comments