When writing code for application.py ran into the fact that in if I can’t set a specific condition. This problem is related to the fact that I am trying to access the non-existent value of the array I selected from SQL .
I attach the code:
creator = db.execute("SELECT username AS name FROM history WHERE added=:added", added=added) creator = creator[0]["name"] anName = db.execute("SELECT username FROM history WHERE idea=:idea AND added=:added AND username!=:username AND deleted=:deleted", idea=idea, added=added, username=name, deleted=deleted) yourName = db.execute("SELECT username FROM history WHERE idea=:idea AND type=:type AND files=:files AND description=:description AND user_id=:user_id AND username=:username AND added=:added AND deleted=:deleted", idea=idea, type=type1, files=files, description=description, user_id=session["user_id"], username=name, added=added, deleted=deleted) if not anName and not yourName: ... elif anName != None: if anName[0]["username"] == creator: ... elif yourName != None: if yourName[0]["username"] == creator: ... As you can see, the anName and yourName can also be None .
Accordingly, to save the code from an error, I first set anName != None . In this case, the browser should have skipped if , the condition in which is incorrect. However, as I understand it, the browser reads the condition even inside the wrong if and with anName == None , and yourName != None still gives an error
if yourName[0]["username"] == creator: IndexError: list index out of range
Question: Can I limit the browser from reading the conditions, the values in which will be equal to None ?
len()never happens None - andreymal