0

I want to change the variable 'COUNT' to 0 at specific time.

But after the work of function 'init()', 'COUNT' is still not initialized.

What's wrong?

import schedule
import time
import datetime

COUNT = 0

def init():
    COUNT = 0
    print(COUNT)
    print("init")
    return COUNT

schedule.every().day.at("13:05:50").do(init)

try :


    while True :

        now = datetime.datetime.now()
        schedule.run_pending()

        COUNT = COUNT +1

        print(now)
        print(COUNT)

        time.sleep(5)

except KeyboardInterrupt :
    print("EXIT")
  • 1
    Global variables are evil. Try to find a better way to accomplish what you need. – Mark Ransom Mar 31 '21 at 04:28
  • This is likely because when you do an assignment, `COUNT` inside the method refers to a local variable instance. In order to tell the interpreter to use the global instance, as the first line of the method, type `global COUNT`. – M Z Mar 31 '21 at 04:31

0 Answers0