def update_file(fname, pattern, replacement):
    """Update the contents of a file, replacing pattern with replacement."""
    with open(fname, encoding="utf-8") as fobj:
        old_text = fobj.read()

    new_text = re.sub(pattern, replacement, old_text, count=1)

    if new_text != old_text:
        print(f"Updating {fname}")
        with open(fname, "w", encoding="utf-8") as fobj:
            fobj.write(new_text)
Update the contents of a file, replacing pattern with replacement.
igor.py