code: def replace_file(src, dst):
      
      # Try os.replace() which was introduced in Python 3.3
      # (this should work on POSIX as well as Windows systems).
      try:
          os.replace(src, dst)
          return
      except AttributeError:
          pass
      # Try os.rename() which is atomic on UNIX but refuses to overwrite existing
      # files on Windows.
      try:
          os.rename(src, dst)
          return
      except OSError as e:
          if e.errno != errno.EEXIST:
              raise
      # Finally we fall back to the dumb approach required only on Windows.
      # See https://bugs.python.org/issue8828 for a long winded discussion.
      os.remove(dst)
      os.rename(src, dst)
docs: Overwrite a file (in an atomic fashion when possible).
  
      :param src: The pathname of the source file (a string).
      :param dst: The pathname of the destination file (a string).