ASCII delimited files

Al Christians achrist at easystreet.com
Wed Nov 10 23:16:48 EST 1999


There's a trick with files of delimited fields.  If a string field
contains a delimiter (e.g. a comma in a csv file), then the field
gets enclosed in quotes.  The handling of quotes is probably trickier,
IDK what the rules are if a field starts with or contains a single or
double quote mark.  I think I remember that some spreadsheets used tp
routinely enclose all strings in quotes in CSV files, but I'm not sure.

What I usually wind up doing to circumvent these problems with delimited
files is loading them back into a spreadsheet, typically the same one
that wrote them (I suppose that a database program would 
offer the same option), and then I write them out as tab-delimited. 
Tabs within fields are just about never in a lifetime in my work, so
far. 


Al


"Thomas A. Bryan" wrote:
> 
> "Thomas A. Bryan" wrote:
> 
> > class DelimParserField:
> >     def __init__(self, name):
> >         self.name = name
> >     def convert(self,value):
> >         return value
> >     def verify(self,value):
> >         pass
> >
> 
> One important thing that I didn't point out.  The "name" member
> is the column's name.  (Remember that I was thinking of
> delimited files for import into a database when I wrote these
> classes.)
> 
> Thus, a more sensible application might have something like
> employeeListParser = DelimFldParser((EnumField('Department',('HR','IT')),
>                                      DelimParserField('Name'),
>                                      NumericRngField('Salary',0,500000)))
> 
> If anyone uses this stuff, I'd be interested in hearing about it.
> 
> ---Tom




More information about the Python-list mailing list