mercredi 28 mars 2018

Python Mulitple For loops with common else

my code at the minute has 2 lists Exercise and Weight. These both contain the contents of generated entry boxes. When the lists are being saved to the database I need to make sure that no empty boxes are submitted, to solve this I am writing a validation algorithm to check if any of the boxes are empty, this is the code so far:

for item in Exercise:
    if item == '':
        self.CreateError.configure(fg = "red")
        connection.commit()

for item in Weight:
    if item == '':
        self.CreateError.configure(fg = "red")
        connection.commit()
else:
    values = zip(Exercise, Weight, ID)
    cursor.executemany("INSERT INTO Exercises(Exercise, Weight, ID) VALUES(?, ?, ?)", values)        
    connection.commit()

My problem is that I have two for loops which both have the same else. However I do not know how to create this so the else is activated if either of both of the items in the list are empty.

Aucun commentaire:

Enregistrer un commentaire