Reputation: 181
I'm very new at Python and I trying to insert data from SQL to a CSV. I have the following code:
sql = cursor.execute("SELECT field_a, field_b, field_c FROM TableA LIMIT 500")
result=cursor.fetchall()
fp = open('dataset.csv', 'w')
myFile = csv.writer(fp)
myFile.writerows(result)
fp.close()
But when I see the CSV created I have multiple blank lines. What I am doing wrong?
Upvotes: 0
Views: 78
Reputation: 267
Python 2.7:
fp = open('dataset.csv', 'wb')
Python 3.x:
fp = open('dataset.csv', 'w', newline='')
Upvotes: 1