0
votes

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:

  1. USER1
  2. USER2
  3. USER3
  4. USER4
  5. USER5
  6. USER6
  7. USER7
  8. 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.

1
If you print your 'rows' variable, the data should look similar to the dataset in that question where elt1 is 'USER1' and elt2 is empty. Seems like a similar problem. - AK47

1 Answers

0
votes

Your user is a tuple with 1 element, just get the first element.

print(user[0])