Reputation: 37
import sqlite3
username=input(print("Username?"))
password=input(print("Password?"))
connection= sqlite3.connect("Logininfo.db")
c = connection.cursor()
IDuser=c.execute('SELECT Username, Password FROM LoginInfo WHERE Username= ? AND Password= ?', (username,password)).fetchone()
print(IDuser)
The data that should be returned from this code is "Hello1" and "Password1" (Without the quotemarks). Instead it outputs "('Hello1', 'Password1')".
A few questions, why does it do this?
How can I retrieve this data without the brackets and quotemarks i.e "('Hello1'," would become "Hello1"
The code also prints out "None" before asking for both the username and password why does it do this and how can I fix it?
Upvotes: 0
Views: 68
Reputation: 7840
To answer your first question, the quotes are there to tell you that it is a string. They are not actually a part of your username or password, so it shouldn't be a problem. Similarly, the brackets are there to tell you that this is a sequence (specifically, a tuple). Python has to get two strings to you, and this is the usual way in which it is done. If this causes a problem for you, then you need to explain why.
To answer your second question, None
is printed because you're calling print()
inside the input()
functions. The return value of print()
is None
. Printing the prompt is already integral to input()
, so there's no need to do that. Just input("Username?")
will suffice.
Upvotes: 1
Reputation: 11
fetchone() returns one "tuple" or the result of the queryset "object", you can access the individual values much like an array
try print(IDuser[0]) and it will print "Hello1".
Please refer to https://docs.python.org/2/library/sqlite3.html and search fetchone() call for more info.
Upvotes: 1