TEXT MANIPULATION (in CSV format)

David C. Ullrich ullrich at math.okstate.edu
Thu Jun 15 11:01:36 EDT 2000


Bill Scherer <scherbi at bam.com> wrote in article
<3948E40C.2425B170 at bam.com>...
> 
> 
> Robin Porter wrote:
> 
> > I am wondering how difficult it would be to use PYTHON to go through a
> > CSV (Comma separated value) formatted file, take two of the fields and
> > merge them into one field.
> >
> > An example would be:
> >
> > Field 1             Field 2
> >
> > "K"           ,       "1234"
> >
> > I want to change to:
> >
> > Field 1
> >
> > K1234
> >
> 
> Easy:
> 
> -----------------------
> #untested...
> import string
> 
> split = string.split
[...] 
> This will work fine if your original file is not huge.

	Except that I'm pretty sure that CSV allows commas _in_
a field if the field is enclosed in quotes. (There's probably a
good reason for CSV, I guess. Seems much simpler to me
to use a separator that does not occur in text but which does
occur on keyboards, like "|", and then to _disallow_ the
separator in fields. Then string.split works.)



More information about the Python-list mailing list