Skip to content

Instantly share code, notes, and snippets.

@stefanmonkey
Created January 8, 2014 07:42
Show Gist options
  • Save stefanmonkey/8313196 to your computer and use it in GitHub Desktop.
Save stefanmonkey/8313196 to your computer and use it in GitHub Desktop.
dict cursor
#!/usr/bin/python
# -*- coding: utf-8 -*-
import MySQLdb as mdb
con = mdb.connect('localhost', 'testuser', '123456', 'testdb')
with con:
cur = con.cursor(mdb.cursors.DictCursor)
cur.execute("SELECT * FROM Writers LIMIT 4")
rows = cur.fetchall()
for row in rows:
print row["Id"], row["Name"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment