Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import and use csvkit in a Python script

I feel like this is a silly question. I've found a python library I need to use. Specifically csvkit . I need to use this in an existing application I've created. However, all of the example usage I've been able to see is from the command line where arguments are passed like this:

in2csv ne_1033_data.xlsx > data.csv

Would I be able to import this and use it within my application? Something along the lines of:

from csvkit import in2csv
in2csv(ne_1033_data.xlsx, data.csv)

Thanks for helping me out. I'm sure I'm misunderstanding something...

like image 875
kevin.w.johnson Avatar asked Feb 12 '15 17:02

kevin.w.johnson


2 Answers

Quoting from the csvkit manual:

import csvkit

Is what you are looking for.

After importing, I'm assuming that the command syntax and data flow are similar to that of the python csv module. Again this is based on the csvkit manual.

like image 96
JoErNanO Avatar answered Sep 22 '22 11:09

JoErNanO


You should import convert and then use convert.xls2csv :

from csvkit import convert
inputfile = open(file.csv)
convert.xls2csv(inputfile)
like image 32
lizzie Avatar answered Sep 25 '22 11:09

lizzie