0

I have script1.py, which containes a function with two variables, variable1 and variable2. The value of these variables get updated every x seconds. If script1.py is run as the main script, it has an endless loop to update variable1 and variable2. The function itself however does not have that endless loop.

Instead, I want to import that function into script2.py and run there with an endless loop. Since the values of variable1 and variable2 are updated continiously, I need to get these new values somehow into script2.py . I tried to do that by

    while True:
    import upload
    time.sleep(10)

but python checks if the module has already been imported and, if yes, won´t import it again. How can I get the updated variables from script1.py into script2.py every x seconds?

Thanks in advance!

maki
  • 35
  • 4
  • This is a really complicated way to go about a simple task, why don't you just make some variables, say `x` and `y` in the changing module and import them into the current file at the very start? That way the variables belong to both files, and every time those variables change, you can detect them in the present file. – Robo Mop May 25 '21 at 10:10
  • 1
    Does this answer your question? [How do I unload (reload) a Python module?](https://stackoverflow.com/questions/437589/how-do-i-unload-reload-a-python-module) – Kemp May 25 '21 at 10:10

0 Answers0