(path, data)
Write data to a temporary file, then move to the destination path.
Write data to a temporary file, then move to the destination path.
Write data to a temporary file then move to the destination path .
def file_write_safe(path, data):
    '''Write data to a temporary file, then move to the destination path.'''
    fh = tempfile.NamedTemporaryFile(mode='w', delete=False)
    fh.write(data)
    fh.close()
    cmd = 'mv "%s" "%s"' % (fh.name, path)
    sh(cmd)
def file_write_safe ( path , data ) : fh = tempfile . NamedTemporaryFile ( mode = 'w' , delete = False ) fh . write ( data ) fh . close ( ) cmd = 'mv "%s" "%s"' % ( fh . name , path ) sh ( cmd )