Is it possible to read a variable from script a.py with a independent excuted script b.py
Example: a.py
#!/usr/bin/env python3
import time
i = 0
def run():
global i
print(i)
i = i+1
def get_i():
return i
def main():
pass
if __name__ == "__main__":
while True:
run()
time.sleep(5)
print("Stopped")
b.py
#!/usr/bin/env python3
import a
print(a.get_i())
If b.py is executed it will print 0 but i want it to print the current state of i as set in a.py, so i has to be greater than 0.
I tried already with an extra c.py where i is saved as global variable an then c.py is imported in a.py and b.py but it is the same behaviour: b.py prints the initial value of i and not the value wich is set in a.py
Notice: a.py is started before b.py and is still running because of the while loop and then b.py is executed.