Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'skip:[ 20': 0.04; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; "'';": 0.16; '24,': 0.16; 'clipped': 0.16; 'fine.': 0.16; 'globals.': 0.16; 'language?': 0.16; 'least.': 0.16; 'naming': 0.16; 'semicolon': 0.16; 'somewhere.': 0.16; 'temperatures': 0.16; 'text?': 0.16; 'true:': 0.16; 'underscores': 0.16; 'words.': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'written': 0.21; 'code,': 0.22; 'programming': 0.22; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'skip:+ 20': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'certainly': 0.24; 'copied': 0.24; 'sorry,': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'help!': 0.26; 'gets': 0.27; 'header:In- Reply-To:1': 0.27; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; '"': 0.31; 'this.': 0.32; 'stuff': 0.32; 'another': 0.32; 'text': 0.33; 'url:python': 0.33; 'received:google.com': 0.35; 'there': 0.35; 'module.': 0.36; 'url:listinfo': 0.36; 'useful': 0.36; 'thanks': 0.36; 'url:org': 0.36; 'wrong': 0.37; 'list': 0.37; 'list.': 0.37; 'clear': 0.37; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'skip:[ 10': 0.38; 'fact': 0.38; 'pm,': 0.38; 'previous': 0.38; 'explain': 0.39; 'skip:& 20': 0.39; 'either': 0.39; 'url:mail': 0.40; 'read': 0.60; 'skip:o 30': 0.61; 'skip:t 30': 0.61; 'range': 0.61; 'skip:+ 10': 0.65; 'to:addr:gmail.com': 0.65; 'between': 0.67; 'brain': 0.68; '\xc2\xa0\xc2\xa0': 0.74; 'goal': 0.75; 'end.': 0.84; 'temperature': 0.84; 'joel': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=AuE0Cs3gBWn5QIZHM9tliNQCXk4HzjV7kSR1+9teKfg=; b=mX6vIni2+Cdh+QKEN0sHNxirQYZsvAl6PG8xA3kdtaOIgaNRVKVblzAlncJH9Im0tK O2bEBxGmZ3JU2+Oh2Dwr8GnSW7hj4mcEam18roiqPEkr7stKvVtoBevBHCpB2l4AAnfy EFO1XORYfksQAuFKtH3BqwA1IloVir4XOwW47yO9KR5Wv4YCReEDu/bKls7vWp72Vc71 PqasQ+PAXrScPGQIfpLdqQrjDebgsOqJ3r16qa0fVGfnvXD3B0ODGL5GHDzjTOlrouLV suCJcvRqibNtsT/dWDrYuQt2FMry/r/U54LWu6l5Ynz25eo9W2q7znJM6Cs5dQ2h83gM /3Ig== MIME-Version: 1.0 X-Received: by 10.220.3.144 with SMTP id 16mr1244195vcn.33.1387908636589; Tue, 24 Dec 2013 10:10:36 -0800 (PST) In-Reply-To: <5414cedd-6e54-43d0-995b-fe116d4c8225@googlegroups.com> References: <9ad01eef-baf0-4018-833e-0b4dce4b9b85@googlegroups.com> <5414cedd-6e54-43d0-995b-fe116d4c8225@googlegroups.com> Date: Tue, 24 Dec 2013 13:10:36 -0500 Subject: Re: Variables in a loop, Newby question From: Joel Goldstick To: vanommen.robert@gmail.com Content-Type: multipart/alternative; boundary=001a11c3cbce43c48504ee4ba934 Cc: "python-list@python.org" 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: 178 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387908644 news.xs4all.nl 2955 [2001:888:2000:d::a6]:38174 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62688 --001a11c3cbce43c48504ee4ba934 Content-Type: text/plain; charset=UTF-8 On Tue, Dec 24, 2013 at 12:54 PM, wrote: > import time > global Sens_Raw1, Sens_Raw2, Sens_Raw3, Sens_Raw4, Sens_Raw5, Sens_Raw6, > Sens_Raw7, Sens_Raw8, Sens_Raw9, Sens_Raw10 > while True: > sensorids = ["28-0000054c4932", "28-0000054c9454", > "28-0000054c9fca", "28-0000054c4401", "28-0000054dab99", "28-0000054cf9b4", > "28-0000054c8a03", "28-0000054d$ > It looks like the previous line is clipped at the end. It needs a closing " and a closing ] at least. > avgtemperatures = [] > What is the above line for. It never reappears below > for sensor in range (len(sensorids)): > temperatures = [] > You never use this either > Sens_Raw = [] > Or this. > text = ''; > No semicolon in python! > 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 > > > > 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. > Again, not clear what you need. You certainly don't need globals. You may want to collect all of the Sens_Raw stuff in a list. If you want that list to useful to other code, you will need to put it in a module. Read about namespaces. There is nothing wrong with naming things with underscores between the words. In fact its recommended. Sorry, my brain is spinning. This code is useless. Why don't you try to explain what you are trying to accomplish, and you will get better answers. As it stands, you perhaps copied this from somewhere. What is the data that gets written to text? Have you any programming skill, perhaps with another language? > Thanks for any help! > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com --001a11c3cbce43c48504ee4ba934 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable



On Tue, Dec 24, 2013 at 12:54 PM, <vanommen.robert@gmail.= com> wrote:
import time
global Sens_Raw1, Sens_Raw2, Sens_Raw3, Sens_Raw4, Sens_Raw5, Sens_Raw6, Se= ns_Raw7, Sens_Raw8, Sens_Raw9, Sens_Raw10
while True:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 sensorids =3D ["28-0000054c4932", &qu= ot;28-0000054c9454", "28-0000054c9fca", "28-0000054c440= 1", "28-0000054dab99", "28-0000054cf9b4", "28= -0000054c8a03", "28-0000054d$

It looks like the previous line is clipped= at the end.=C2=A0 It needs a closing " and a closing ] at least.
= =C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 avgtemperatures =3D []
What is the above line for.=C2=A0 It never reappears below
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 for sensor in range (len(sensorids)):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 temperatures =3D []=
You never use this either
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Sens_Raw =3D []
Or this.
=C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 text =3D &= #39;';
=C2=A0 =C2=A0 =C2=A0 =C2=A0
No semicolon in python!
= =C2=A0
=C2=A0 =C2=A0 =C2=A0 =C2=A0 = while text.split("\n")[0].find("YES") =3D=3D -1:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 tfile =3D open("/sys/bus/w1/dev= ices/"+ sensorids[sensor] +"/w1_slave")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 text =3D tfile.read()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 tfile.close()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 time.sleep(0.1)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 secondline =3D text= .split("\n")[1]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 temperaturedata =3D= secondline.split(" ")[9]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 temperature =3D flo= at(temperaturedata [2:])
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 temperatures.append= (temperature / 1000)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 print "Sensor = ", sensor + 1, temperatures
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # Sens_Raw(sensor) = =3D temperatures



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.

Again, not clear w= hat you need.=C2=A0 You certainly don't need globals.=C2=A0 You may wan= t to collect all of the Sens_Raw stuff in a list.=C2=A0 If you want that li= st to useful to other code, you will need to put it in a module.=C2=A0 Read= about namespaces.
There is nothing wrong with naming things with underscores betwe= en the words.=C2=A0 In fact its recommended.

Sorry, my b= rain is spinning.=C2=A0 This code is useless.=C2=A0 Why don't you try t= o explain what you are trying to accomplish, and you will get better answer= s.=C2=A0 As it stands, you perhaps copied this from somewhere.=C2=A0 What i= s the data that gets written to text?=C2=A0 Have you any programming skill,= perhaps with another language?


Thanks for any help!
--
https://mail.python.org/mailman/listinfo/python-list



--
--001a11c3cbce43c48504ee4ba934--