0

When running the following code I would like to be able to store the returned values in a variable as a string. However when I run the code it will return the first name from the database in this format

[(u'Kiefer',)]

What would I need to change in order to just return a clean string? I was thinking I could use strip although I have never used it on a tuple (not even sure if you can) but I was hoping there is a more elegant way. Also I am using the sqlite3 module.

def search_db(self,ID,FName,LName):
    #try:
    FName +='%'
    LName += '%'
    self.cur.execute(("""SELECT FirstName FROM members WHERE FirstName LIKE '%s'\
    AND LastName LIKE '%s'""") % (FName, LName))
    value = (self.cur.fetchall())
    print(value)
    #except:
        #print('failed')


cla = Database()
cla.search_db(1,'K','D')
1
  • 1
    value[0][0] is your string Commented Dec 19, 2013 at 0:08

1 Answer 1

2

You need to access the first element of the list, which is the tuple, then the first element of the tuple, so:

value[0][0]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.