[Baypiggies] Want to redirect output to a csv file
Shannon -jj Behrens
jjinux at gmail.com
Fri Apr 25 02:54:16 CEST 2008
What you're asking for would require quite a bit of intelligence, and
it would require you to look at all of the data, or at least a bunch
of rows. Look at how OpenOffice and Excel deal with this problem.
I've heard that Excel messes it up half the time (I could be wrong. I
don't use Excel). In OpenOffice, there's a wizard where you get to
play with the options and look at the result until you get it right.
-jj
On Wed, Apr 23, 2008 at 10:46 AM, Charles Merriam
<charles.merriam at gmail.com> wrote:
> Hmm.. I'm finding it hard to process arbitrary CSV files. The csv
> module and its dialects option don't handle the "take whatever the
> user gives me and assume the obvious". Anyone have an csv
> reimplementation?
>
>
>
>
> On Tue, Apr 22, 2008 at 3:52 AM, Shannon -jj Behrens <jjinux at gmail.com> wrote:
> > Ha! I wrote very much that same script this week!
> >
> > $ ./blueplate/parsing/cleancuttsv.py -h
> > Usage: cleancuttsv.py [options]
> >
> > Options:
> > -h, --help show this help message and exit
> > --assert-head=FIELD1\tFIELD2\t...
> > assert that the first line of the file matches this
> > --delete-head delete the first line of input
> > -n NUM, --num-fields=NUM
> > assert that there are this many fields per line
> >
> > Small world.
> >
> > -jj
> >
> >
> >
> > On Sun, Apr 20, 2008 at 9:09 PM, Jason Culverhouse
> > <jason at mischievous.org> wrote:
> > >
> > > 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
> > >
> > > _______________________________________________
> > > Baypiggies mailing list
> > > Baypiggies at python.org
> > > To change your subscription options or unsubscribe:
> > > http://mail.python.org/mailman/listinfo/baypiggies
> > >
> >
> >
> >
> > --
> > I, for one, welcome our new Facebook overlords!
> > http://jjinux.blogspot.com/
> >
> >
> > _______________________________________________
> > Baypiggies mailing list
> > Baypiggies at python.org
> > To change your subscription options or unsubscribe:
> > http://mail.python.org/mailman/listinfo/baypiggies
> >
>
--
I, for one, welcome our new Facebook overlords!
http://jjinux.blogspot.com/
More information about the Baypiggies
mailing list