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)

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 )
write data to a temporary file .