Re: How best to archive in CSV format
Re: How best to archive in CSV format
- Subject: Re: How best to archive in CSV format
- From: Bob Ippolito <email@hidden>
- Date: Wed, 18 May 2005 17:02:56 -0400
On May 18, 2005, at 4:49 PM, Ronald Oussoren wrote:
On 17-mei-2005, at 4:36, Bob Ippolito wrote:
On May 16, 2005, at 10:12 PM, Brian Smith wrote:
On May 17, 2005, at 9:43 AM, Bob Ippolito wrote:
One alternative is to look at PyObjC, because Python ships with
a csv module.. though it's not optimal since current versions
have a limitation such that it only knows how to deal with
bytestrings, not unicode, so you have to encode everything into
utf-8 before putting it into the csv and decode it from utf-8
after getting it out.
I've used python to read a csv file and it can't handle mac line
endings too, which the files I need to read have. So, with
PyObjC, I used NSString's componentsSeparatedByString: method to
read the file, so I have found this to be useful, but obviously
you have to experiment given on csv files you have. I did have
to strip some quote marks from the ends of the array of strings,
but I was able to still do it easily with NSString and NSArray
methods.
Fields containing quotes and comma's require additional work. Using
the csv module requires less thought.
Yeah, stripping quotes is not enough, because you'll end up with
columns that are broken in the middle due to a comma being present..
of course, you can hack around this until it works, but I'd highly
recommend using a mostly correct implementation of a CSV parser in
the first place :)
Actually it can read Mac line endings (bare '\r') just fine if you
open the file with universal newlines (the 'U' mode). I do this
all the time.
Technically that is not correct, you need to use
lineterminator='\r' in the dialect.
It's perfectly correct for *reading* csv files. Universal newlines
will simply convert '\r' to '\n' before the csv reader sees it,
allowing you to read csv files of any line ending (even mixed)
without issues.
For writing csv files, you might care about the line terminator.. but
for reading them, it's VERY convenient to use universal newlines
especially when you're dealing with both the Windows and Macintosh
version of Excel, interchangeably, for example.
-bob
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden