Can't reset index in view function
I am calling a view function and that view function calls another function on a 1 min timer. The issue I am having is resetting the 'i' value.
Can someone help me figure out how to fix this or or come up with a new way for me to do this.
I want to call the getABC function on a one minute timer and have it loop through the 'listOfStrings' and then have it start the list back over once it reaches the end.
I have a feeling I am looking over something and making it much more complicated than it needs to be.
def viewfunction(request):
listOfStrings = [...list Of Strings ]
i = 0
def func():
for each in range(i-60, i-1):
getABC(listOfStrings[each], each)
if listOfStrings[each] == 'ZYXI':
i = 0
return
schedule.every(1).minutes.do(lambda: func())
while True:
i += 1
schedule.run_pending()
time.sleep(1)
The issue with the code above is the 'i' in "for each in range(i-60, i-1):" gets the UnboundLocalError: local variable 'i' referenced before assignment.
So then I try to pass in the i as a param and then return it but idk how would I access the return variable.
def viewfunction(request):
listOfStrings = [...list Of Strings ]
i = 0
def func(i):
for each in range(i-60, i-1):
getABC (listOfStrings[each], each)
if listOfStrings[each] == 'ZYXI':
i = 0
return
schedule.every(1).minutes.do(lambda: func(i))
while True:
i += 1
schedule.run_pending()
time.sleep(1)
End result is I need the getABC function to be called every 1 minute, while passing in each iteration as a param on each call. And then once reaching the end of the list, restart and start back at the beginning of the list. A infinite loop.