@@ -219,25 +219,30 @@ def add_modelling_assumptions(self, estimation_model: Estimator): # pylint: dis
219
219
return
220
220
221
221
def _append_to_file (self , line : str , log_level : int = None ):
222
- """ Appends given line(s) to the current output file. If log_level is specified it also logs that message to the
222
+ """Appends given line(s) to the current output file. If log_level is specified it also logs that message to the
223
223
logging level.
224
224
:param line: The line or lines of text to be appended to the file
225
225
:param log_level: An integer representing the logging level as specified by pythons inbuilt logging module. It
226
226
is possible to use the inbuilt logging level variables such as logging.INFO and logging.WARNING
227
227
"""
228
- with open (self .output_path , "a" , encoding = 'utf-8' ) as f :
229
- f .write (line + "\n " , )
228
+ with open (self .output_path , "a" , encoding = "utf-8" ) as f :
229
+ f .write (
230
+ line + "\n " ,
231
+ )
230
232
if log_level :
231
233
logger .log (level = log_level , msg = line )
232
234
233
235
@staticmethod
234
236
def check_file_exists (output_path : Path , overwrite : bool ):
235
- """ Method that checks if the given path to an output file already exists. If overwrite is true the check is
237
+ """Method that checks if the given path to an output file already exists. If overwrite is true the check is
236
238
passed.
237
239
:param output_path: File path for the output file of the JSON Frontend
238
240
:param overwrite: bool that if true, the current file can be overwritten
239
241
"""
240
- if not overwrite and output_path .is_file ():
242
+ if overwrite :
243
+ file = open (output_path , "w" , encoding = "utf-8" )
244
+ file .close ()
245
+ elif output_path .is_file ():
241
246
raise FileExistsError (f"Chosen file output ({ output_path } ) already exists" )
242
247
243
248
@staticmethod
@@ -257,7 +262,7 @@ def get_args(test_args=None) -> argparse.Namespace:
257
262
parser .add_argument (
258
263
"-w" ,
259
264
help = "Specify to overwrite any existing output files. This can lead to the loss of existing outputs if not "
260
- "careful" ,
265
+ "careful" ,
261
266
action = "store_true" ,
262
267
)
263
268
parser .add_argument (
0 commit comments