Posted By

vasilije on 02/08/09


Tagged

mysql python


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jeremydouglass


Simple csv dump script


 / Published in: Python
 

  1. SELECTQ="SELECT * FROM category"
  2. FILENAME="dump.csv"
  3.  
  4. import MySQLdb
  5. import csv
  6.  
  7. db = MySQLdb.connect(host="localhost", user="root", passwd="", db="sakila")
  8. dump_writer = csv.writer(open(FILENAME,'w'), delimiter=',',quotechar="'")
  9. cursor = db.cursor()
  10. cursor.execute(SELECTQ)
  11. result = cursor.fetchall()
  12. for record in result:
  13. dump_writer.writerow(record)
  14.  
  15. db.close()

Report this snippet  

You need to login to post a comment.