[Tutor] Wanted: module to parse out a CSV line
Terry Carroll
carroll@tjc.com
Wed Dec 11 12:14:02 2002
On Wed, 11 Dec 2002, Magnus Lycka wrote:
> I was just about to suggest that you used one of the three
> modules below. It's nice to see that someone has made the
> effort to search the net before asking here! :)
Hey, I'm new to Python, so I'm going to be asking a lot more questions
here, and this was my first post -- I figured it's best to start off at
least *looking* a little clueful. :-)
> > 1. ASV, from <http://tratt.net/laurie/python/asv/>
> > Nice, but it reads in an entire file that is assumed to be
> > CSV-formatted.
>
> There is an input_from_file method, but you don't have to use
> that. Use input instead.
Thanks. The docs are a little sparse, and don't have any hint that that's
possible. I tried reading through the Python code, but, as I said, I'm
still a newbie to Python, and couldn't really follow it yet. I'll keep
that in mind.
> > 2. A CSV module from
> > <http://www.object-craft.com.au/projects/csv/documentation.html>
>
> If you are using Win32, you can use one of the following binaries:
> Win32 Python 2.1 binary: csv.pyd 20K Nov 20 2002
> Win32 Python 2.2 binary: csv.pyd 20K Nov 20 2002
You know, maybe 30 minutes after I posted to the list (and after writing
Dave separately, based on an old message I found where he first gave a
URL, now dead, for the the Windows version, I looked at the download page
and saw it. I downloaded it, installed it, and it works fine for me.
The hazards of programming too far past bedtime.
> It seems the space after the comma confuses CSV regarding the use
> of double quotes. I've seen a lot of files with whitespace after
> the comma, so this is not what I would like.
Actually, my real project doesn't have the spaces following the commas,
so I'm fine. My example did not properly mirror my requirement.
For what it's worth (not that I'm implying that Python should emulate
Perl), I tried my bad example with the perl module Text::CSV, and it
choked, returning an error and giving up on the parse.
> I think it would be a good thing to have parsers/importers/exporters for
> both CSV (and fixed format) in the standard library. We just need some
> kind of consensus on how they should behave I guess...
>From what I gathered in my search, there's a long way to go on that
consensus. :-)
Thanks very much for the help, I appreciate it.
--
Terry Carroll |
Santa Clara, CA | "The parties are advised to chill."
carroll@tjc.com | - Mattel, Inc. v. MCA Records, Inc.,
Modell delendus est | no. 98-56577 (9th Cir. July 24, 2002)