Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:question': 0.10; 'python': 0.11; "'';": 0.16; 'fine.': 0.16; 'loop.': 0.16; 'mechanism.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'temperatures': 0.16; 'true:': 0.16; 'wrote:': 0.18; 'module': 0.19; 'trying': 0.19; 'file,': 0.19; 'written': 0.21; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'file.': 0.24; 'source': 0.25; 'help!': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'dec': 0.30; 'statement': 0.30; 'another': 0.32; 'text': 0.33; 'sense': 0.34; 'add': 0.35; 'version': 0.36; 'thanks': 0.36; 'should': 0.36; 'list': 0.37; 'list.': 0.37; 'skip:o 20': 0.38; 'skip:[ 10': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:t 30': 0.61; 'range': 0.61; "you're": 0.61; "you'll": 0.62; "you've": 0.63; 'email addr:gmail.com': 0.63; 'skip:+ 10': 0.65; 'goal': 0.75; 'temperature': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Variables in a loop, Newby question Date: Tue, 24 Dec 2013 13:42:45 -0500 References: <9ad01eef-baf0-4018-833e-0b4dce4b9b85@googlegroups.com> <5414cedd-6e54-43d0-995b-fe116d4c8225@googlegroups.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: dpc6744192029.direcpc.com In-Reply-To: <5414cedd-6e54-43d0-995b-fe116d4c8225@googlegroups.com> User-Agent: Groundhog Newsreader for Android X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387910492 news.xs4all.nl 2944 [2001:888:2000:d::a6]:43799 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62690 On Tue, 24 Dec 2013 09:54:48 -0800 (PST), vanommen.robert@gmail.com wrote: You should always start by mentioning python version and o.s. > import time > global Sens_Raw1, Sens_Raw2, Sens_Raw3, Sens_Raw4, Sens_Raw5, Sens_Raw6, Sens_Raw7, Sens_Raw8, Sens_Raw9, Sens_Raw10 The global statement makes no sense here, as you're not inside a function. Everything you've written is global. That means global to one module or source file. If you need to access data from another module you'll use import, and if you need to share with another process you'll need to use a file, a pipe, a queue, or some other mechanism. > while True: > sensorids = ["28-0000054c4932", "28-0000054c9454", "28-0000054c9fca", "28-0000054c4401", "28-0000054dab99", "28-0000054cf9b4", "28-0000054c8a03", "28-0000054d$ > avgtemperatures = [] > for sensor in range (len(sensorids)): > temperatures = [] > Sens_Raw = [] You're clobbering the list every time around the loop. Move this line before the loop. > text = ''; > while text.split("\n")[0].find("YES") == -1: > tfile = open("/sys/bus/w1/devices/"+ sensorids[sensor] +"/w1_slave") > text = tfile.read() > tfile.close() > time.sleep(0.1) > secondline = text.split("\n")[1] > temperaturedata = secondline.split(" ")[9] > temperature = float(temperaturedata [2:]) > temperatures.append(temperature / 1000) > print "Sensor ", sensor + 1, temperatures > # Sens_Raw(sensor) = temperatures Use Sens_Raw.append () to add to the end of the list. > This is the program I am trying to adjust. The goal is to make Sens_Raw1 to 10 global so I can use it in other programs on the Raspberry Pi. The print Sensor wordks fine. > Thanks for any help! -- DaveA