locrian.elder
locrian.elder

Reputation: 9

SQL returning sqlite3 cursor object instead of value

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 ()```

Upvotes: 0

Views: 1807

Answers (1)

Ananthu M
Ananthu M

Reputation: 107

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))

Upvotes: 1

Related Questions