You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defwrite_to_file(self, new_problem, overwrite=False):
""" :param overwrite: Whether to overwrite the file at 'new_problem' if it exists :type overwrite: bool """
. . .
Describe the solution you'd like
Check for the existence of the file new_problem, and do not overwrite it unless overwrite=True.
One solution: simply raise an error.
ifoverwriteornotos.path.exists(new_problem):
# write the file as normalreturnelifos.path.isfile(new_problem):
raiseFileExistsError(new_problem)
elifos.path.isdir(new_problem):
raiseIsDirectoryError(new_problem):
. . .
Describe alternatives you've considered
Or, if the file exists and overwrite == False, back up the original file with some sort of identifier, and then write to the requested filename.
defget_next_backup_fname(new_problem):
base_name, extension=os.path.splitext(new_problem)
timestamp=int(time.time()) # OR use strftime('%Y%m%d%H%M%S') for human-readablenew_fname=f"{base_name}_backup_{timestamp}{extension}"# If user going faster than one file per secondindex=1whileos.path.exists(new_file):
new_file=f"{base_name}_backup_{timestamp}_{index}{extension}"index+=1returnnew_fname
New function signature:
Describe the solution you'd like
Check for the existence of the file
new_problem
, and do not overwrite it unlessoverwrite=True
.One solution: simply raise an error.
Describe alternatives you've considered
Or, if the file exists and
overwrite == False
, back up the original file with some sort of identifier, and then write to the requested filename.UUID:
Timestamp:
Additional context
Related to pyOpenSci review here: pyOpenSci/software-submission#205 (comment)
The text was updated successfully, but these errors were encountered: