Database Python Tutorial

import psycopg
def dictfetchone(cur):
    seq = cur.fetchone()
    if seq == None:
        return seq
    result = {}
    colnum = 0
    for column in cur.description:
        result[column[0]] = seq[colnum]
        colnum += 1
    return result
dbh = psycopg.connect('dbname=jgoerzen user=jgoerzen')
print "Connection successful."
cur = dbh.cursor()
cur.execute("SELECT * FROM myTable")
while 1:
    row = dictfetchone(cur)
    if row == None:
        break
    print row
dbh.close()