-
Notifications
You must be signed in to change notification settings - Fork 18
pyio.parse_csv
Parses the fields of a CSV-file to tables of strings.
pyio.parse_csv(file) | Parameter | Type | Description |
|---|---|---|
file |
file handle |
The file that should be read |
| Type | Description |
|---|---|
{ { string* }* } |
A table that, for each row, contains a tables of strings |
For example, a text file with the following content
Author,Poem,Year
Lord Byron,She walks in beauty, 1814
Friedrich Schiller,"Freude, schöner Götterfunken"would result in the following lua tables
{ { "Author", "Poem", "Year" },
{ "Lord Byron", "She walks in beauty", " 1814" },
{ "Friedrich Schiller", "Freude, schöner Götterfunken" } }The encoding of the text-file is automatically detected. UTF8, UTF8 with BOM, UTF16LE with BOM and ASCII are supported. If the encoding can be chosen freely, the either UTF8 with BOM or UTF16 with BOM are recommended. For UTF8 without BOM / ASCII, there's a small risk that the encoding might not be detected correctly.
For line endings, Windows and Unix line endings (CR+LF and LF) are equally supported.
The default field separator is the comma. Quoted fields are supported. Separators (commas) and newlines are allowed in quoted field. To include a literal quotation mark