title: Read db and write to file in python
body: <p>I have a connection to mysql db and making queries with that but I need them write to file immediately, what is the easy way of do this ? </p>
  
  <pre><code>conn = MySQLdb.connect(host="localhost",user="root",passwd="",db="mydb")
  cursor = conn.cursor(MySQLdb.cursors.DictCursor)
  cursor.execute("SELECT * FROM books")
  </code></pre>
  
  <p>..</p>