0

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?

1
  • In the code result is never used. Commented Feb 24, 2018 at 22:31

1 Answer 1

1

Python 2.7:

fp = open('dataset.csv', 'wb')

Python 3.x:

fp = open('dataset.csv', 'w', newline='')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.