import cs304dbi as dbi # ========================================================== # The functions that do most of the work. def get_connection(): db_name = 'wmdb' dbi.conf(db_name) print(f'connecting to {db_name}') return dbi.connect() def getPeople(conn): '''Returns the name and birthdate of all the entries in the person table, as a list of dictionaries. ''' if conn is None: conn = get_connection() curs = dbi.dict_cursor(conn) curs.execute('select name,birthdate from person') return curs.fetchall() # ========================================================== # This starts the ball rolling, *if* the file is run as a # script, rather than just being imported. if __name__ == '__main__': conn = get_connection() pl = getPeople(conn) for person in pl: print('{name} born on {date}' .format(name=person['name'], date=person['birthdate']))