Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting unresolved reference error in line 5

I want to print change, after 2 sec but I am getting unresolved reference error in line 5. What should I do?

import threading
def inchange():
    global change = 0
    threading.Timer(1, inchange).start()
    change = change + 2
    print(change)

if __name__ == "__main__":
    inchange()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The problem is how you access global change.

Here is the code:

import threading

change = 0

def inchange():
    global change
    threading.Timer(1, inchange).start()
    change = change + 2
    print(change)

if __name__ == "__main__":
    inchange()

Output:

2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading