ASCII delimited files

D'Arcy J.M. Cain darcy at vex.net
Thu Nov 11 09:40:43 EST 1999


Roger Irwin <irwin at mail.com> wrote:
> Is there any function or module available for parsing ASCII delimited files,
> before I go and re-invent the wheel writing my own.

> BTW, I know it is simple to do, but I was thinking along the lines that a
> 'standard' could easily be substituted for a C version for large files.

I use delimited.py which works pretty good.  Here's an example usage.

import delimited
for l in delimited.split_delimited(open('datafile.csv').read()):
    print "Field 1: %s\nField 2: %s\n\n" % (l[0], l[1])

I couldn't find this on the Python or Starship sites but you can get it
from http://www.deja.com/getdoc.xp?AN=448769706.  One small problem with
it is that it doesn't handle commas within quoted strings properly.  I
am going to look at this today for another project and I will post it
here when I have something.

-- 
D'Arcy J.M. Cain <darcy at caingang.com>      |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on         
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.




More information about the Python-list mailing list