Is anyone happy with csv module?

massimo s. devicerandom at gmail.com
Wed Dec 12 10:04:09 EST 2007


On Dec 12, 2:58 pm, Neil Cerutti <horp... at yahoo.com> wrote:
> On 2007-12-11, massimo s. <deviceran... at gmail.com> wrote:
>
> > Hi,
>
> > I'm struggling to use the python in-built csv module, and I
> > must say I'm less than satisfied. Apart from being rather
> > poorly documented, I find it especially cumbersome to use, and
> > also rather limited. What I dislike more is that it seems
> > working by *rows* instead than by *columns*.
>
> It is very *thoroughly* documented, which is a style that won't
> suit every purpose.
> > So I have some questions:
> > 1) Is there a good tutorial, example collection etc. on the csv
> > module that I'm missing?
>
> Just skip to 9.1.5 Examples, and you'll be on your way.

If by "thoroughly" you mean "it actually describes technically what it
is and does but not how to really do things", yes, it is thoroughly
documented.
The examples section is a joke. It gives good examples for the
simplest usage cases (good), then it almost immediately digs into
details like the Unicode stuff, leaving aside the rest. DictWriter and
DictReader are absent from the examples. And also the Sniffer.

And, as a sidenote, why putting something useful like the unicode
decoder-encoders in the example section instead of inserting them
directly in the library?

I don't want to be mean with the author of csv and its docs. I now
understand there are excellent reasons for csv to be done the way it
is, and it's only my fault if I didn't see that before. I also know
first hand that documenting code is hard and boring stuff. Kudos to
anyone doing that, but in the Example section there is surely room for
improvement. It's probably OK for people doing things row-by-row and
that already know perfectly their way in and out all that, but if this
thread teaches us something, is that the same thing can be used for
vastly different purposes.

I will try to submit a patch to the documentation based on examples
coming from here and what I will learn by digging into csv.

> > 3) In case anyone else is as unhappy as me, and no tutorial
> > etc. enlighten us, and no alternative is present, anyone is
> > interested in an alternative csv module? I'd like to write one
> > if it is the case.
>
> I was intimidated by it at first, implemented my own reader
> (mostly as a fun parsing exercise), used that for a while, and
> then threw it out.
>
> I advise you to spend time staring at the examples, and use the
> simplest example the suits your needs. Also search this archives
> of this group for examples.

OK, thanks!

As for people advicing xlrd/xlrwt: thanks for the useful tip, I didn't
know about it and looks cool, but in this case no way I'm throwing
another dependency to the poor users of my software. Csv module was
good because was built-in.

m.



More information about the Python-list mailing list