On 18 feb 2008, at 20:51, Dean Matthews wrote:

I need to convert a CSV file to delimited.

There are commas that should not be converted i.e. "Joe Smith, Phd"

These commas are enclosed in quotes as above.

How can I replace the commas with tabs without affecting the commas enclosed in quotes?

The following Python should get you started:

import csv

csv.register_dialect('excel-embed', delimiter=',',
    quoting=csv.QUOTE_MINIMAL, skipinitialspace=True, quotechar='"',
    doublequote=False, escapechar="\\")

reader = csv.reader(open("test.csv", "rb"), dialect="excel-embed")
writer = csv.writer(open("out.txt", "wb"), dialect="excel-tab")

for row in reader:
    writer.writerow(row)


# Maarten

--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to