I have this code:
def warnTime(i):
i += 1
print(i)
t = Timer(20, warnTime)
t.start()
The rest of the code works just fine, but when it comes to this part, it raises the TypeError.
When I try to get the variable value it does the same thing.
When I try to do i = 0 before the function it just returns 0.
I tried calling the function with argument, like warnTime(0) or variable = warnTime(0), but it didn’t work.
>Solution :
Assuming you are using the Threading Timer, you’ll need to pass the initial value of i, change your code to:
from threading import Timer
def warnTime(i):
i += 1
print(i)
t = Timer(20, warnTime, args=[0])
t.start()