parsing CSV file

Joined
Mar 18, 2009
Messages
1
Reaction score
0
I'm another relative new Python scripter and came across the forums looking for more information on using the csv module. Here's my scenario:

I have a csv file with about 20 fields. One of the fields contains information that needs to be split into multiple fields. The data is separated by a space, but could have between 0 and 4 values.

I've started by looking at the reader and writer classes by reading the cvs and writing a couple columns to a new csv. All I've managed, though, is to read the csv, print columns to the console by index, and write the entire contents of the original csv to a new one. This is what I've got:
Code:
import csv
reader = csv.reader(open("C7956-2-24-09REV-B.csv", "rb"))
writer = csv.writer(open("output1.csv", "wb"))
                            
for row in reader:
    print row[0], row[12]
    writer.writerow(row)

Should I be looking at the dictreader and dictwriter classes instead?

dylan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top