How can I maintain commas when exporting a CSV file in Python for Airtable?

I’m trying to export a table using Python into CSV format specifically for Airtable. When I open the resulting CSV file in Excel, everything seems fine. However, when I upload the file to Airtable, it struggles with strings that include commas, leading to issues.

Here’s an example of what I get:

firstname|lastname|instrument|
john,doe,"violin,piano,guitar"| <-- ERROR
mary|smith|guitar

Compared to what I want to achieve:

firstname | lastname | instrument            |
-----------+----------+-----------------------+
john      | doe      | violin, piano, guitar |
mary      | smith    | guitar                |

Is there a way to adjust my CSV export in Python to resolve this? Is there an alternative method to handle this issue? Below is how I’m currently exporting my CSV:

with open('CRMtest.csv', 'w', newline='') as csvfile:
    linewriter = csv.writer(csvfile, delimiter=":", quotechar='"')
    for i in range(len(list_names)):
        linewriter.writerow([row1[i], row2[i], row3[i]])

Each of my row_X variables contains strings, some of which have commas. Here’s an example:

row1 = 'firstname','john','mary'
row2 = 'lastname','doe','smith'
row3 = 'instrument','violin, piano, guitar','guitar'

your delimiter’s mixed up. airtable wants standard csv format with commas, not colons. check your row data structure too - you might have tuples instead of lists, which’ll mess up indexing when writing rows.

I had the same problem when exporting to Airtable. You’re using colons (:slight_smile: as delimiters, but Airtable needs commas. Just switch your CSV writer to use commas and add proper quoting for strings that contain commas. Here’s the fix:

import csv

with open('CRMtest.csv', 'w', newline='') as csvfile:
    linewriter = csv.writer(csvfile, delimiter=',' , quotechar='"', quoting=csv.QUOTE_MINIMAL)
    for i in range(len(list_names)):
        linewriter.writerow([row1[i], row2[i], row3[i]])

The csv.QUOTE_MINIMAL automatically wraps fields with commas in quotes, so Airtable can read your file properly.