File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77
88[project ]
99name = " spotpython"
10- version = " 0.15.23 "
10+ version = " 0.15.24 "
1111authors = [
1212 { name =" T. Bartz-Beielstein" , email =" tbb@bartzundbartz.de" }
1313]
Original file line number Diff line number Diff line change @@ -2295,9 +2295,18 @@ def parallel_plot(self, show=False) -> go.Figure:
22952295 fig .show ()
22962296 return fig
22972297
2298- def save_experiment (self , filename = None ) -> None :
2298+ def save_experiment (self , filename = None , overwrite = True ) -> None :
22992299 """
23002300 Save the experiment to a file.
2301+
2302+ Args:
2303+ filename (str):
2304+ The filename of the experiment file.
2305+ overwrite (bool):
2306+ If `True`, the file will be overwritten if it already exists. Default is `True`.
2307+
2308+ Returns:
2309+ None
23012310 """
23022311 # Remove or close any unpickleable objects, e.g., the spot_writer
23032312 self .close_and_del_spot_writer ()
@@ -2333,6 +2342,11 @@ def save_experiment(self, filename=None) -> None:
23332342 if filename is None and PREFIX is not None :
23342343 filename = get_experiment_filename (PREFIX )
23352344
2345+ # Check if the file already exists
2346+ if filename is not None and os .path .exists (filename ) and not overwrite :
2347+ print (f"Error: File { filename } already exists. Use overwrite=True to overwrite the file." )
2348+ return
2349+
23362350 # Serialize the experiment dictionary to the pickle file
23372351 if filename is not None :
23382352 with open (filename , "wb" ) as handle :
You can’t perform that action at this time.
0 commit comments