我一直在测试这个csv包data.csv.
我已经设法使写入CSV工作。我对clojure/lisp还是个新手。
我不能弄清楚(通过测试或通过文档),是如何在csv中添加数据到新行。
API文档是这样说的:
write-csv
function
Usage: (write-csv writer data & options)
Writes data to writer in CSV-format.
Valid options are
:separator (Default ,)
:quote (Default ")
:quote? (A predicate function which determines if a string should be quoted. Defaults to quoting only when necessary.)
:newline (:lf (default) or :cr+lf)
但是我不知道如何使用它。
我正在尝试为以下代码添加新行:
(defn writeCSV [name]
(with-open [writer (io/writer filePath)]
(csv/write-csv writer
[[name 2]])))
其中name
被添加到下一行。
使用io/writer
的:append
选项:
(require
'[clojure.data.csv :as csv]
'[clojure.java.io :as io])
(with-open [writer (io/writer "/tmp/foo.csv" :append true)]
(csv/write-csv writer [["name" 1]]))
(with-open [writer (io/writer "/tmp/foo.csv" :append true)]
(csv/write-csv writer [["name" 2]]))
(println (slurp "/tmp/foo.csv"))
;;=>
name,1
name,2