game=input("enter student name to update report card: ")
nn=game.replace(" ", "_")
mycursor.execute("show tables")
klm = mycursor.fetchall()
if (nn,) in klm:
b=int(input("enter sno: "))
mycursor.execute("select * from {} where sno='{}'".format(nn,b))
xer=mycursor.fetchall()
else:
print("no student record found")
this does not execute the if statement it directly goes to the else even though i have table name some_one, it shows no record found
CodePudding user response:
nn=game.replace(" ", "_")
has 2 spaces in your code
Try with
nn=game.replace(" ", "_")
has one space
game=input("enter student name to update report card: ")
nn=game.replace(" ", "_")
print(nn)
#output
enter student name to update report card: some one
some_one
CodePudding user response:
You are searching for the tuple (nn,)
in your table names. Just try searching for the string itself like this:
if nn in klm: