Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Importing constantly changing variables Date: Sat, 26 Dec 2015 10:11:53 -0700 Lines: 17 Message-ID: References: <944a9d35-dc31-4074-8d56-bb6e9a0d1d15@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de UHssHYV9dHCrX05NxMF87genzga1QtuPyD+BTStMB2/g== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'imported.': 0.09; 'file,': 0.15; 'iteration.': 0.16; 'printing.': 0.16; 're-read': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'seconds,': 0.16; 'seconds.': 0.16; 'subject:changing': 0.16; 'wrote:': 0.16; 'versions': 0.20; 'changes': 0.20; '2015': 0.20; 'trying': 0.22; 'am,': 0.23; 'code.': 0.23; 'dec': 0.23; 'sat,': 0.23; 'header:In- Reply-To:1': 0.24; 'module': 0.25; 'error': 0.27; '(e.g.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'see,': 0.27; 'function': 0.28; 'values': 0.28; 'print': 0.30; 'code': 0.30; 'putting': 0.30; 'generally': 0.32; 'run': 0.33; 'source': 0.33; 'changing': 0.34; 'correctly': 0.34; 'file': 0.34; 'running': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'done': 0.35; 'conditions.': 0.35; "isn't": 0.35; 'but': 0.36; 'instead': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'data': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'save': 0.60; 'your': 0.60; 'leading': 0.61; '26,': 0.72; 'sounds': 0.76; 'confusing': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=2swGkOB6GM+WlZiLq8ejf/JkkICLuH60mI2OGNTjY4U=; b=c8x+o+qRVBvtVm5gd1TJjiXNSs7WDE3cGfi2PDyet5AdxSEh5zPcUzDPfIZpFlsMWT NnBBDFwE1KnDbzJVzO9L5+9ZWybnWPOE5lccCzdFAv2GIintW3btthomq8JYw4EGZePT ZxO10IFuFw/yXu2wnU1OMLrv7+TJeYHo4Yh03nUUaAzKW0RxvkpUIeMW+I2WhG9UXyTX ArF7tNC8dHjKlVy9BuKJziDut1h66qaZl5eSZGZS6/E2jID463DpLNTSGCHnIZH5isXc iU46ew2Mvms9Ylh4IXQu7xk8mxMEYwTtjuoqRsudMJJh98TNJFuXzEfVGeGxei6rYxcg DEpw== X-Received: by 10.50.154.5 with SMTP id vk5mr45724464igb.85.1451149952468; Sat, 26 Dec 2015 09:12:32 -0800 (PST) In-Reply-To: <944a9d35-dc31-4074-8d56-bb6e9a0d1d15@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100895 On Sat, Dec 26, 2015 at 8:14 AM, 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.