Skip to content
/ csvtable Public

Nim tools for dealing with CSV files with an API similar to Python's CSVDictReader and -Writer

License

Notifications You must be signed in to change notification settings

apahl/csvtable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Nim tools for dealing with CSV files with an API similar to Python's CSVDictReader and -Writer

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages