Update a pre-filled CSV record

Create a command-line editor for one record in user_data.csv. The file has the columns Name, Age, and Email Address. Show each current value as the default; pressing Enter keeps that value, while entering text replaces it. Write the resulting record back to the same file.

For example, if the stored name is Alex, its prompt should be:

Listing 1 shows the prompt with the current name.

Listing 1: Example input prompt when the stored name is Alex.
Name [Alex]:

The supplied create_sample_file function makes this exercise independent of any earlier file-writing task.

Use the supplied helpers and function template in Listing 2.

Listing 2: Sample-file and input helpers with the template for updating a user record.
import csv
from pathlib import Path


FIELD_NAMES = ["Name", "Age", "Email Address"]


def create_sample_file(file_path: Path) -> None:
    with file_path.open("w", newline="", encoding="utf-8") as file:
        writer = csv.DictWriter(file, fieldnames=FIELD_NAMES)
        writer.writeheader()
        writer.writerow(
            {
                "Name": "Alex",
                "Age": "19",
                "Email Address": "alex@example.com",
            }
        )


def prompt_with_default(label: str, current_value: str) -> str:
    response = input(f"{label} [{current_value}]: ").strip()
    return response or current_value


def update_user_record(file_path: Path) -> dict[str, str]:
    """Prompt for replacements, rewrite the CSV, and return the saved row."""
    raise NotImplementedError

Test with a disposable path: call create_sample_file, update at least one field, then reopen the file and verify that it still contains one header and one data record.