mercredi 25 février 2015

If-else clause in Python Statement

I am trying to check the output of few functions and if there is no error I move to next function. So I have added a while loop and few if statements to handle the errors:



success = True
while success:
err, msg = function1()
if not err:
err, msg = function2()
if not err:
err, msg = function3()
if not err:
err, msg = function4()
else:
print msg
success = False
else:
print "function2 fails"
sucess = False
else:
print "function1 fails"
success = False


Is it a better way to avoid if,else , how can I redesign the code for this purpose?


Aucun commentaire:

Enregistrer un commentaire