I'm wrinting a script to write query results rows in a csv file. The data is email adresses, like this :
For now, my code writes my results in the csv file like this :
('[email protected]'), ('[email protected]'), ('[email protected]'),
How can I use next lines instead of rows ?
EDIT : It seems that my query gives me data between brackets like ('[email protected]'),
Here is the code :
import pymysql
import csv
db = pymysql.connect(host="localhost", port=3306, user="foo", passwd="bar", db="db")
cursor = db.cursor()
query3 = """SELECT email FROM tmp"""
cursor.execute(query)
data = cursor.fetchall()
list = []
for row in data :
value = str(row)
list.append(value)
file = open('file.csv', 'wb')
data = csv.writer(file)
data.writerow(list)
cursor.close()
db.close()
file.close()