No description
Find a file
2020-04-15 09:57:44 +02:00
.gitignore changed directory structure 2017-01-11 11:38:29 +01:00
csvtable.nim changed API 2018-06-12 15:20:57 +02:00
csvtable.nimble mkDir doc 2018-06-12 15:49:31 +02:00
LICENSE Initial commit 2016-10-31 16:36:48 +01:00
README.md no support for quoted strings 2020-04-15 09:57:44 +02:00
test.csv more elaborate example 2017-02-05 20:20:07 +01:00

csvtable nimble

Tools for handling CSV files (comma or tab-separated) with an API similar to Python's CSVDictReader and -Writer. The values in the rows are assigned to tables as values where the keys are the corresponding headers.

Please note: version 0.3.0 changes the API, have a look at the example and the doc. For the old API. use releases <0.3.0.

Example usage

  import csvtable, strutils
  var
    csvIn = newCSVTblReader("test.csv")
  echo csvIn.headers
  let
    headersOut = @["position", "total"]  # all headers must be known at the creation of the file
  var csvOut = newCSVTblWriter("tmp.csv", headersOut)
  for dIn in csvIn:
    var dOut = newTable[string, string]()
    dOut["position"] = dIn["position"]
    dOut["total"] = $(dIn["day1"].parseInt + dIn["day2"].parseInt)
    csvOut.writeRow(dOut)
  csvOut.close

Limitations

This is a very simple implementation of a CSV parser. It currently does not support quoted strings.

Installation

nimble install csvtable

Documentation

Run nimble gendoc. Documentation can then be found in doc/csvtable.html.