Importing constantly changing variables

Ian Kelly ian.g.kelly at gmail.com
Sat Dec 26 12:11:53 EST 2015


On Sat, Dec 26, 2015 at 8:14 AM,  <ariklapid.swim at gmail.com> wrote:
> As you can see, I want the program to print all values each 5 seconds.
> When I run the file "main.py" it does print values every 5 seconds, BUT when I manually change
> the values (e.g. airTemperture = 30 instead of 24) and save the file, nothing changes -
> the old values keep on printing.

Changing the source code of a module isn't going to affect that module
in a running program if it's already been imported. You can use the
importlib.reload function to force a module to be reloaded, but this
is generally anti-recommended. If not done correctly it can result in
multiple versions of the module being simultaneously in use, leading
to confusing error conditions.

It sounds like you're not trying to update the code anyway, just the
data used in the code. For that, you'd be better off putting the data
in a data file that your "sensors.py" would read from and re-read on
every iteration.



More information about the Python-list mailing list