我在python中创建用户/登录类型的东西,并且需要遍历sql数据库中的某个列以附加到python列表,以便新用户不能在我的数据库中使用用户名。我不知道从哪里开始,但这就是我所拥有的
import sqlite3
users = sqlite3.connect('D:\lel.db')
uquery = users.cursor()
name_list=[]
def createtable():
uquery.execute('''CREATE TABLE if NOT EXISTS users (userforename text, usersurname text,username text,password text,userscore,userdifficulty text)''')
def adduserintotable(userforename, usersurname, username, password,userscore,userdifficulty,uquery):
uquery.execute('''INSERT INTO users (userforename,usersurname,username,password,userscore,userdifficulty)
VALUES (?,?,?,?,?,?)''', (userforename, usersurname, username, password, userscore,userdifficulty))
users.commit()
def newuser():
uquery = users.cursor()
userforename = (str(input("What is your forename? ")))
usersurname = (str(input("What is your Surname? ")))
username = (str(input("whats your username ")))
password = (input("What is your passcode? "))
userscore = (0)
userdifficulty = ("")
diffchosen = False
#name_list=SELECT username FROM users
#for row in users.execute("name_list"):
# print (row)
#print(name_list)
while diffchosen == False:
difficulties = ["easy","medium","hard"]
for difficulty in difficulties:
print (difficulty)
print ("Choose a difficulty ")
while userdifficulty != "easy" and userdifficulty != "medium" and userdifficulty != "hard":
try:
userdifficulty = str(input("Please insert a valid difficulty "))
except:
print ("you inputted an incorrect difficulty")
diffchosen = True
adduserintotable(userforename, usersurname, username, password, userscore,userdifficulty,uquery)
users.commit()
createtable()
newuser()
PS我已经掌握了数据库中的所有数据以及用户如何输入自己的数据
谢谢:D