I have a long tab-delimited text file that I'd like to convert into csv
format so I can read it into a statistics package. 

I've been using Excel to do the format conversion up till now, but now I
have more rows than Excel can handle, and would like to avoid going
through Excel if possible. 

 

I've found the csv module but am confused by its documentation, as I am
with the few threads on the subject generally. 

 

Here's what I've tried to do:

 

import csv

inputFileList = file('input.txt').readlines()

writer = csv.writer(file('output.csv', 'wb'))

writer.writerows(inputFileList)

del writer

 

When I try to open the resulting file in Excel (I've used a sample file
of 100 rows), however, it appears that I'm delimiting every character,
as each character has its own column. The rows in the original text file
are combinations of integers and character strings (some of which
include double quotes). Do I need to alter the 'dialect' or what?

 

Many thanks in advance for your help!

 

Nick

 

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to