Your summarize_plan takes a list of customer dicts. Where does that list come from in real life?
Stripe exports a CSV. I open it in Excel, check the headers, manually retype the values into Python. Which defeats the point.
Instead of opening a file, take the CSV text as a string argument — split it on newlines, parse the header row to get column names, then parse each data row. The Pyodide runtime has no filesystem, so passing text directly is actually the cleanest pattern:
lines = csv_text.strip().split("\n")
headers = lines[0].split(",")
for line in lines[1:]:
values = line.split(",")
row = dict(zip(headers, values))
print(row)zip(headers, values) — what does that do exactly?
zip pairs items from two lists by position: zip(['a','b'], [1, 2]) produces [('a', 1), ('b', 2)]. dict(...) converts those pairs into {'a': 1, 'b': 2}. That's how you turn a CSV row into a named dict in one line. Here's the full function:
def parse_customer_csv(csv_text: str) -> list:
lines = csv_text.strip().split("\n")
headers = [h.strip() for h in lines[0].split(",")]
customers = []
for line in lines[1:]:
values = line.split(",")
row = dict(zip(headers, [v.strip() for v in values]))
row["mrr"] = float(row.get("mrr", 0))
row["seats"] = int(row.get("seats", 1))
row["name"] = clean_customer_name(row.get("name", ""))
customers.append(row)
print(f"Parsed {len(customers)} customers")
return customersWait — I can pass the CSV text as a string argument and parse it inside the function? So I never need actual files in the test environment. That's elegant.
Exactly. Pure functions that take text in and give dicts out compose better than file readers. Your Monday CSV paste becomes parse_customer_csv(csv_text) — and you never open Excel.
I just replaced my entire 'import CSV to Excel' ritual with a string-parsing function. The Stripe export goes straight into Python.
Always cast numeric fields immediately after parsing — float(row['mrr']) right after dict(zip(...)). CSV gives you strings everywhere; functions downstream expect numbers.
CSV text is a multi-line string. Split on newlines to get rows; split each row on comma to get cells.
lines = text.strip().split("\n")
headers = lines[0].split(",")
for line in lines[1:]:
row = dict(zip(headers, line.split(",")))zip and dictzip(a, b) pairs elements by position. dict(zip(keys, values)) builds a named dict from two lists.
CSV values arrive as strings. Cast numeric fields immediately: float(row['mrr']). Silent bug if skipped — comparisons like mrr > 100 will fail on string '149.0'.
Your summarize_plan takes a list of customer dicts. Where does that list come from in real life?
Stripe exports a CSV. I open it in Excel, check the headers, manually retype the values into Python. Which defeats the point.
Instead of opening a file, take the CSV text as a string argument — split it on newlines, parse the header row to get column names, then parse each data row. The Pyodide runtime has no filesystem, so passing text directly is actually the cleanest pattern:
lines = csv_text.strip().split("\n")
headers = lines[0].split(",")
for line in lines[1:]:
values = line.split(",")
row = dict(zip(headers, values))
print(row)zip(headers, values) — what does that do exactly?
zip pairs items from two lists by position: zip(['a','b'], [1, 2]) produces [('a', 1), ('b', 2)]. dict(...) converts those pairs into {'a': 1, 'b': 2}. That's how you turn a CSV row into a named dict in one line. Here's the full function:
def parse_customer_csv(csv_text: str) -> list:
lines = csv_text.strip().split("\n")
headers = [h.strip() for h in lines[0].split(",")]
customers = []
for line in lines[1:]:
values = line.split(",")
row = dict(zip(headers, [v.strip() for v in values]))
row["mrr"] = float(row.get("mrr", 0))
row["seats"] = int(row.get("seats", 1))
row["name"] = clean_customer_name(row.get("name", ""))
customers.append(row)
print(f"Parsed {len(customers)} customers")
return customersWait — I can pass the CSV text as a string argument and parse it inside the function? So I never need actual files in the test environment. That's elegant.
Exactly. Pure functions that take text in and give dicts out compose better than file readers. Your Monday CSV paste becomes parse_customer_csv(csv_text) — and you never open Excel.
I just replaced my entire 'import CSV to Excel' ritual with a string-parsing function. The Stripe export goes straight into Python.
Always cast numeric fields immediately after parsing — float(row['mrr']) right after dict(zip(...)). CSV gives you strings everywhere; functions downstream expect numbers.
CSV text is a multi-line string. Split on newlines to get rows; split each row on comma to get cells.
lines = text.strip().split("\n")
headers = lines[0].split(",")
for line in lines[1:]:
row = dict(zip(headers, line.split(",")))zip and dictzip(a, b) pairs elements by position. dict(zip(keys, values)) builds a named dict from two lists.
CSV values arrive as strings. Cast numeric fields immediately: float(row['mrr']). Silent bug if skipped — comparisons like mrr > 100 will fail on string '149.0'.
You receive Stripe exports as CSV text — comma-separated rows with a header line. Write `parse_customer_csv(csv_text)` that splits on newlines, parses each row into a dict, casts mrr to float and seats to int, and returns the list of customer dicts — for example, a two-row CSV with headers 'name,plan,mrr,seats' should produce a list of two dicts.
Tap each step for scaffolded hints.
No blank-editor panic.