I am creating an options menu based on a a user initials column in a database so that a user can chose his initials and my script will log it to a database.
I am stuck with a simple problem but I do not know the question to ask to find the answer:
#! /usr/bin/env python
import os
import sys
import qrtools
import pyqrcode
import datetime as dt
import MySQLdb
import MySQLdb as mdb
def tape_recovery_connect():
con = mdb.connect('mydb.my.server.com', 'user', 'password', 'database')
return con
def close_tape_recovery():
con.close
con = tape_recovery_connect()
with con:
cur = con.cursor()
cur.execute("""SELECT UserInit FROM users""")
close_tape_recovery()
count = cur.rowcount
print count
rows = cur.fetchall()
for k, row in enumerate(rows):
# print ("row is %s" % (row))
print (str(k+1) + ". " + "".join(row))
print ("Select your initials 1 - %i" % (count))
user_num = int(raw_input(": " ))
user = row[user_num-1]
print user
When I run the program I get mostly what I want:
- USER1
- USER2
- USER3
- USER4
- USER5
- USER6
- USER7
- USER8
Select your initials 1 - 8
: 2
('USER2',)
But I cannot figure out how to get what I want without the parenthesis and other stuff.
I also cannot figure out why the formmating is quoting my output to put the last three lines all after USER8 but I guess this gets the general idea.