0

I'm trying to retrieve a password from a user table, but when I assign a SELECT to the variable pw_august_borne, it returns as an sqlite3.Cursor object. I need it to return the password associated with August Borne, and I found that using a for loop to iterate over THE ONE SINGLE VALUE in the variable pw_list returns the wanted output. I know I could just use the iteration method brigade it is a tuple, but I want to find a better way. What do you recommend? Output after running script: helloWORLD <sqlite3.Cursor object at 0xb6314720>

conn = sqlite3.connect ('login_test2.db')

c = conn.cursor ()

'''lists all passwords (pw) in users_tbl'''
pw_list = c.execute ("SELECT pw FROM users_tbl WHERE name='August Borne'")
for row in pw_list :
    print (row[0])

pw_august_borne = c.execute ('SELECT pw FROM users_tbl WHERE name="August Borne"')
print (pw_august_borne)

conn.close ()```

5
  • Also, if I use a generator to print it, I get <generator object <genexpr> at 0xb63148b0>. What's the difference? Commented Nov 8, 2019 at 4:33
  • Your first version looks correct (the second is not). What is your question? Commented Nov 8, 2019 at 4:33
  • I just thought at first that it should return the same thing, but now I see that because it's a tuple is simply returning the fact that is a tuple in pw_august_borne Commented Nov 8, 2019 at 4:37
  • Is helloWORLD August Borne's password? Commented Nov 8, 2019 at 4:37
  • Yes, it is. That's what I thought I could obtain using pw_august_borne but it just shows is an object. Commented Nov 9, 2019 at 3:28

1 Answer 1

1

use list() to get the details other than the cursor object.

pw_august_borne = c.execute ('SELECT pw FROM users_tbl WHERE name="August Borne"')
print(list(pw_august_borne))
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.