-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcsv_parser.psh
More file actions
24 lines (20 loc) · 659 Bytes
/
Copy pathcsv_parser.psh
File metadata and controls
24 lines (20 loc) · 659 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Reads a CSV file with the csv module and prints its rows
from csv import parse_csv_file, format_csv;
let rows = parse_csv_file("examples/data/test_data.csv");
if (rows == nil) {
$println("Error reading test_data.csv");
return;
}
for (let var i = 0; i < rows.len; ++i) {
$println("Row " + (i + 1).to_s() + ":");
let row = rows[i];
for (let var j = 0; j < row.len; ++j) {
$println(" Cell " + (j + 1).to_s() + ": " + row[j]);
}
}
// Rows can be turned back into CSV text, with quoting where it is needed
$println("");
$println(format_csv([
["name", "quote", "note"],
["Emily", "She said \"hi\"", "one, two"],
]));