Help splitting CVS data

Dave Angel d at davea.name
Sun Jan 20 17:21:33 EST 2013


On 01/20/2013 05:04 PM, Garry wrote:
> I'm trying to manipulate family tree data using Python.
> I'm using linux and Python 2.7.3 and have data files saved as Linux formatted cvs files
> The data appears in this format:
>
> Marriage,Husband,Wife,Date,Place,Source,Note0x0a
> Note: the Source field or the Note field can contain quoted data (same as the Place field)
>
> Actual data:
> [F0244],[I0690],[I0354],1916-06-08,"Neely's Landing, Cape Gir. Co, MO",,0x0a
> [F0245],[I0692],[I0355],1919-09-04,"Cape Girardeau Co, MO",,0x0a
>
> code snippet follows:
>
> import os
> import re
> #I'm using the following regex in an attempt to decode the data:
> RegExp2 = "^(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\[[A-Z]\d{1,}\])\,(\d{,4}\-\d{,2}\-\d{,2})\,(.*|\".*\")\,(.*|\".*\")\,(.*|\".*\")"
> #

Well, you lost me about there.  For a csv file, why not use the csv module:


import csv

ifile  = open('test.csv', "rb")
reader = csv.reader(ifile)


For reference, see http://docs.python.org/2/library/csv.html

and for sample use and discussion, see

http://www.linuxjournal.com/content/handling-csv-files-python

-- 
DaveA



More information about the Python-list mailing list