'Python : Event Based Sequence depended on Each other
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
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bharel |
