I have the below piece of code.
def create_user():
print("hello")
def stop_service():
print("world")
def retry(operation, attempts):
for n in range(attempts):
if operation():
print("Attempt " + str(n) + " succeeded")
break
else:
print("Attempt " + str(n) + " failed")
retry(create_user, 3)
retry(stop_service, 5)
Initially, I didn't have creat_user and stop_service methods defined. To make this code run I added them. But my question is, for what values of operation will it go in the if clause because with the below code it always goes into the else clause. Maybe we don't need methods at all. Just seeing operation() made me guess I need to have create_user and stop_service as methods. Also if I want to study this, what should I look up for, method calling in Python, or passing method in IF didn't show any results on google.
Aucun commentaire:
Enregistrer un commentaire