#!/usr/local/bin/python2.7 '''Lists all the actors in the database Written Spring 2015 Re-written Spring 2018 Scott D. Anderson ''' import sys import MySQLdb import dbconn2 # ================================================================ # The functions that do most of the work. # The optional arguments make it easy to play with these in the # Python REPL def getNames(conn): '''Returns an array of rows (dictionaries), listing all actors and birthdates''' curs = conn.cursor(MySQLdb.cursors.DictCursor) # results as Dictionaries curs.execute('select name,birthdate from person') return curs.fetchall() # ================================================================ # This starts the ball rolling, *if* the script is run as a script, # rather than just being imported. if __name__ == '__main__': DSN = dbconn2.read_cnf() DSN['db'] = 'wmdb' # the database we want to connect to conn = dbconn2.connect(DSN) actorlist = getNames(conn) for actor in actorlist: print actor['name'], 'born on ',actor['birthdate']