data = '\n'.join(','.join('"%s"' % field for field in row) for row in data)
f = open('data.txt', 'w')
f.write(data)
What's the most efficient way to insert thousands of records into a table (MySQL, Python, Django)