I am new to python. It might seem little obvious but would like to know if there is any easier way in python to do this.
I am trying to count number entries to a function. Requirement is as below:
- Every 5 sec a timer event is triggered through which callback (ev_5ms()) is inturn triggered
- Wait until 20 secods and then clear the counter and start again
I am using the following code
counter = 0
"Callback"
def ev_5s():
if counter < 4:
counter += 1
else
counter = 0
print('Send Message')
t = EventGenerator.TimerEventGenerator(1, ev_1s())
t.start()
Error Traceback:
Traceback (most recent call last):
File "C:/Users/i8479/Desktop/Python/HPP_SM.py", line 28, in <module>
t = EventGenerator.TimerEventGenerator(1, ev_1s())
File "C:/Users/i8479/Desktop/Python/HPP_SM.py", line 21, in ev_1s
if counter < 4:
UnboundLocalError: local variable 'counter' referenced before assignment
I am coding as I would do in c or cpp. How can I do this in python?