RReplacent
Product

Product features · Atomic UTF-8 file replacement

01

Review replace_utf8.py around the point where a closed temporary file replaces the previous UTF-8 contents.

01

Connection

Base URL, credentials and a reachable server.

02

Selection

A model available through the configured endpoint.

03

Capabilities

Context limits and tool support are determined by the model and server.

Atomic UTF-8 file replacement

● ● ●Replacent●
A concrete starting point · Atomic UTF-8 file replacement ×
import os
from pathlib import Path
from tempfile import NamedTemporaryFile

def replace_utf8(path, text):
    if not isinstance(path, (str, Path)) or type(text) is not str:
        raise ValueError("replace.input")
    target, data = Path(path), text.encode("utf-8")
    temporary = None
    try:
        with NamedTemporaryFile(dir=target.parent, prefix=".swap-", delete=False) as out:
            temporary = Path(out.name)
            out.write(data)
        os.replace(temporary, target)
    finally:
        if temporary is not None:
            temporary.unlink(missing_ok=True)
✳Atomic UTF-8 file replacement
✓ ChangesReview before applying ↗
Illustrative workspace
AI coding workspace

Your next change starts here.

Get the Windows app ↗