I have a Python file Running on a Loop that prints out an estimated time for Something to happen. I would like another Python file to import just that and print it out! Exampel:
#loop.py
import datetime
import time
while 1:
moment = datetime.datetime.now()
next_moment = datetime.datetime.now() + datetime.timedelta(minutes = 10)
time.sleep(50)
#Print.py
import datetime
from loop import moment, next_moment
print moment
print next_moment
print "Exit"
But if i Run Print.py it does nothing.(It should say "Exit" right?)
And if i Cancel the skript it says:
^CTraceback (most recent call last):
File "print.py", line 2, in <module>
from loop import moment, next_moment
File "/home/pi/Programming/Tests/loop.py", line 8, in <module>
time.sleep(50)
KeyboardInterrupt
So i guess by importing the scpript loop.py it also runs it. Now is there a way for me to just get the Variables out of this Loop?
Thanks for any answer!