CSV methodology

Rustom Mody rustompmody at gmail.com
Sun Sep 14 10:56:21 CEST 2014

On Sunday, September 14, 2014 2:09:51 PM UTC+5:30, Cameron Simpson wrote:

> If you have a nice regular CSV file, with say 3 values per row, you can go:

>    reader = csv.reader(f)
>    for row in reader:
>        a, b, c - row

I guess you meant:  a, b, c = row  

Also you will want to do appropriate type conversions up front.
eg if the first field is string the second field is int and the third a float

something like
a,b,c = row[0], int(row[1]), float(row[2])

More generally as Terry said csv is not necessarily a appropriate standard
(because there is no standard!!)
If inputting outputting to/from a spreadsheet is required thats ok.

Else there are dozens of others.
My favorite is yml
Json is close enough and getting more traction nowadays
Then of course there's XML which everyone loves to hate -- for reasons similar
to csv it may be required

More information about the Python-list mailing list