# Profile: Python basics. A two-column toy case, not the capstone answer.
import csv
from io import StringIO
def read_two_fields(text):
try:
records = list(csv.reader(StringIO(text), strict=True))
except csv.Error as error:
raise ValueError("malformed CSV quoting") from error
if not records or records[0] != ["code", "units"]:
raise ValueError("expected code,units header")
for position, record in enumerate(records[1:], start=2):
if len(record) != 2:
raise ValueError(f"record {position}: expected 2 fields, got {record!r}")
return records[1:]
sound = "code,units\nR1,unknown\n"
print("Structurally sound:", read_two_fields(sound))
try:
int(read_two_fields(sound)[0][1])
except ValueError:
print("R1 is a value rejection: units remain 'unknown'")
try:
read_two_fields("code,units\nextra,R1,2\n")
except ValueError as error:
print("Ingestion stopped:", error)