I have a sequence of request calls dependent on each other, each one searches on a field in DB or Scrape a website, the sequence stops when a request finds the item
I am using a sequence of if statement pseudo code
if found:
return
else:
call_request(params1)
if found:
return
else:
call_second_request(params2)
I am looking for an optimized way to do this sequence of request calls
CodePudding user response:
You can put the request functions inside a list and use a for
loop:
request_funcs = [call_request, call_second_request, ...]
for func in request_funcs:
result = func()
if result:
return
print("Not found")
If it's the same function, use a while
loop:
found = False
while not found:
found = call_next_request()
return