Is anyone happy with csv module?

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Dec 11 17:50:28 EST 2007


"massimo s." <devicerandom at gmail.com> writes:

> Yes, but maybe I was in the wrong. I'm not so bold to submit patches
> to an official Python module without asking.

Be bold. The worst that can happen is that your patch will be
rejected. Any discussion that happens can only improve your
understanding (and that of others).

> Ability to work by columns together with rows and maybe some random
> access facilities would be nice.

The CSV format doesn't organise naturally into columns, only rows.
However, Python's native constructs make it easy to get the column you
want:

    csv_rows = [
        ["foo", 1, "spam"],
        ["bar", 2, "eggs"],
        ["baz", 3, "beans"],
    ]
    column_1 = [row[1] for row in csv_rows]

> A more user-friendly interface too.

This isn't saying anything about what you want the interface to be
like. What specifically would you change, and what would the result
be?

> Yes, but it's natural for a spreadsheet-like thing to have organized
> columns of data, often.

Perhaps, but that's not relevant. CSV is a serialisation format for
tabular data, and is only "a spreadsheet-like thing" in its heritage.
The CSV data stream is not "spreadsheet-like" at all.

> Often I want those columns to be read into lists, or to write lists
> into columns. The actual csv doesn't allow this naturally.

Python provides those facilities, with easy-to-use syntax for
manipulating them. What more, specifically, do you want the csv module
to do?

> Especially writing is a bit painful.

Again, what specifically would you change, and what would the result
look like?

> (Btw: who is using csv to read >10**6 lines of data?)

Yes, quite often. The csv module provides exactly what I need to turn
a CSV data stream into Python-native data structures. From that point,
Python's own data structures do everything necessary, without needing
specific support in the csv module.

> I googled but apart from some hint here and there of someone
> thinking about writing a pure Python csv module, I found nothing.

Some of your questions need to be elaborated, as above.

-- 
 \     "Reality must take precedence over public relations, for nature |
  `\                            cannot be fooled." —Richard P. Feynman |
_o__)                                                                  |
Ben Finney



More information about the Python-list mailing list