Question: how to export data from database to csv file in python?
Answer: import MySQLdb as dbapi. import sys. import csv. QUERY='SELECT * FROM mydb.people;' db=dbapi. connect(host='localhost',user='root',passwd='password') cur=db. cursor() result=cur. fetchall() c = csv. writer(open('dbdump01.csv', 'wb'))