[Baypiggies] Want to redirect output to a csv file
Jason Culverhouse
jason at mischievous.org
Mon Apr 21 06:09:08 CEST 2008
Justin,
Funny thing... I was reading and writing csv files just now.
I preprocess input files to make sure all the lines have same number
of fields as the header
checkcsv.py < input.csv > good.csv 2>bad.csv
The good lines go to stdout, the bad lines go to stderror.
#!/usr/bin/env python
import csv
import sys
reader = csv.reader(sys.stdin)
error = csv.writer(sys.stderr)
output = csv.writer(sys.stdout)
header = reader.next()
fields = len(header)
output.writerow(header)
for line in reader:
if len(line) == fields:
output.writerow(line)
else:
error.writerow(line)
Jason
On Apr 20, 2008, at 5:24 PM, Tabatchnick, Justin wrote:
> Hi
>
> I am running an imported file and want to redirect the output to a
> csv file , what is the best way to accomplish this ?
>
> Thanks
>
> Justin Tabatchnick
> Intel, Folsom
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/baypiggies/attachments/20080420/eff1867a/attachment.htm
More information about the Baypiggies
mailing list