csv module
Read CSV either as raw rows (list of lists) or as records (list of maps keyed by header). Write CSV from rows.
import "csv" as csv;
import "io" as io;
var text = io.read_file("users.csv");
var rows = csv.parse(text); // [["id","name"], ["1","Alice"], ...]
var records = csv.parse_records(text); // [{id: "1", name: "Alice"}, ...]
print(records[0].name); // Alice
var out = csv.stringify([["id","name"], [1,"Alice"], [2,"Bob"]]);
io.write_file("out.csv", out);
API
| Function | Description |
|---|---|
csv.parse(text) → list of lists | Each inner list is one row's cells. |
csv.parse_records(text) → list of maps | First row treated as headers; subsequent rows become maps keyed by header. |
csv.stringify(rows) → string | rows is a list of lists. Cells are coerced to strings and quoted when needed. |
See also
json— when JSON fits your data better.