Is anyone happy with csv module?

Neil Cerutti horpner at yahoo.com
Thu Dec 13 10:09:05 EST 2007


On 2007-12-12, John Machin <sjmachin at lexicon.net> wrote:
> On Dec 13, 12:58 am, Neil Cerutti <horp... at yahoo.com> wrote:
>> On 2007-12-12, John Machin <sjmac... at lexicon.net> wrote:
>>
>> >> It's clear that I am thinking to completely different usages
>> >> for CSV than what most people in this thread. I use csv to
>> >> export and import numerical data columns to and from
>> >> spreadsheets.
>>
>> > For that purpose, CSV files are the utter pox and then some.
>> > Consider using xlrd and xlwt (nee pyexcelerator) to read
>> > (resp. write) XLS files directly.
>>
>> I can vouch for that advice. I was exporting .xls files to csv
>> text files for over a year before I tried the xlrd
>> solution--the whole process is less cumbersome now, though it
>> was bewildering at first working with Excel in Python.
>> Actually, surprises still crop up now and then, mostly to do
>> with cell types.
>
> Hi Neil, I'd be interested in hearing from you what caused the
> initial bewilderment with xlrd, and could it have been reduced
> by better documentation? What kinds of surprises?

The bewilderment had to do not with xlrd, but with learning the
structure of an Excel spreadsheet. My brain was extremely
resistant to what it didn't want to know. ;-)

The suprises are when a different data type gets returned for
something, like a zip code, whose cases I thought I had covered.
This is not a problem with xlrd either, but with my data source
providing slighly different data, resulting in errors. E.g., the
first time I got a zip+4 instead of a zip.

When I was exporting to csv, I handled those issues by manually
formatting the columns before exporting. This is what made it
cumbersome. I traded that in for the occasional pupu platter of
data. But by using Python directly on the spreadsheet, I have to
fix new problems only *once*.

>> The advantage of working with csv was that everything was a
>> string.
>
> It depends of your point of view. I'd regard that as a
> DISadvantage :-) With xlrd, if you have no expectation about
> the type of data in a cell, but need/want to know, xlrd will
> tell you. If you do have an expectation, you can check if
> actual == expected.

Sorry, my statement was nonsense. My data was only unified before
exporting because I unified it manually, e.g., making a ziptext
column and setting it to =TEXT(ZIP, "00000").

So I'd say the bewilderment and surprise I experience are coming
from my reluctance to learn, and my data, respectively--not from
any property of xlrd.

-- 
Neil Cerutti
To succeed in the world it is not enough to be stupid, you must also be well-
mannered. --Voltaire



More information about the Python-list mailing list