lundi 15 mars 2021

list index out of range despite checking length with "&" operator [duplicate]

I'm checking length of parameters and if it equals a specific value then it should enter if. If not, it should enter into else.

print(len(sys.argv))
if (
    (len(sys.argv) == 9)
    & (sys.argv[8] == "framework")
):
    employeeId = userid + "frame"
    print("frame")
else:
    employeeId = userid

print("userid")

Now passed len(sys.argv) is 7 and "userid" should print but I got the error

list index out of range

Aucun commentaire:

Enregistrer un commentaire