Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #100895

Re: Importing constantly changing variables

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Importing constantly changing variables
Date 2015-12-26 10:11 -0700
Message-ID <mailman.21.1451149955.11925.python-list@python.org> (permalink)
References <944a9d35-dc31-4074-8d56-bb6e9a0d1d15@googlegroups.com>

Show all headers | View raw


On Sat, Dec 26, 2015 at 8:14 AM,  <ariklapid.swim@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Importing constantly changing variables ariklapid.swim@gmail.com - 2015-12-26 07:14 -0800
  Re: Importing constantly changing variables Ian Kelly <ian.g.kelly@gmail.com> - 2015-12-26 10:11 -0700
  Re: Importing constantly changing variables Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-12-26 13:14 -0500
  Re: Importing constantly changing variables Ben Finney <ben+python@benfinney.id.au> - 2015-12-27 10:15 +1100

csiph-web