Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62690
| From | Dave Angel <davea@davea.name> |
|---|---|
| Subject | Re: Variables in a loop, Newby question |
| Date | 2013-12-24 13:42 -0500 |
| References | <9ad01eef-baf0-4018-833e-0b4dce4b9b85@googlegroups.com> <5414cedd-6e54-43d0-995b-fe116d4c8225@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4603.1387910492.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Variables in a loop, Newby question vanommen.robert@gmail.com - 2013-12-24 08:07 -0800
Re: Variables in a loop, Newby question Joel Goldstick <joel.goldstick@gmail.com> - 2013-12-24 11:20 -0500
Re: Variables in a loop, Newby question "Tobias M." <tm@tobix.eu> - 2013-12-24 17:24 +0100
Re: Variables in a loop, Newby question Peter Otten <__peter__@web.de> - 2013-12-24 17:29 +0100
Re: Variables in a loop, Newby question bob gailer <bgailer@gmail.com> - 2013-12-24 12:26 -0500
Re: Variables in a loop, Newby question vanommen.robert@gmail.com - 2013-12-24 09:54 -0800
Re: Variables in a loop, Newby question Joel Goldstick <joel.goldstick@gmail.com> - 2013-12-24 13:10 -0500
Re: Variables in a loop, Newby question Dave Angel <davea@davea.name> - 2013-12-24 13:42 -0500
Re: Variables in a loop, Newby question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-25 13:35 -0500
Re: Variables in a loop, Newby question vanommen.robert@gmail.com - 2013-12-24 10:27 -0800
Re: Variables in a loop, Newby question Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-25 02:54 +0000
Re: Variables in a loop, Newby question Cameron Simpson <cs@zip.com.au> - 2013-12-25 16:42 +1100
Re: Variables in a loop, Newby question Denis McMahon <denismfmcmahon@gmail.com> - 2013-12-25 15:27 +0000
Re: Variables in a loop, Newby question Cameron Simpson <cs@zip.com.au> - 2013-12-26 12:01 +1100
Re: Variables in a loop, Newby question Chris Angelico <rosuav@gmail.com> - 2013-12-26 12:35 +1100
Re: Variables in a loop, Newby question Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-26 16:41 +1100
Re: Variables in a loop, Newby question Dave Angel <davea@davea.name> - 2013-12-26 03:14 -0500
Re: Variables in a loop, Newby question Chris Angelico <rosuav@gmail.com> - 2013-12-26 19:24 +1100
Re: Variables in a loop, Newby question Peter Otten <__peter__@web.de> - 2013-12-25 15:52 +0100
Re: Variables in a loop, Newby question Michael Torrie <torriem@gmail.com> - 2013-12-25 23:34 -0700
Re: Variables in a loop, Newby question Larry Hudson <orgnut@yahoo.com> - 2013-12-25 00:13 -0800
Re: Variables in a loop, Newby question vanommen.robert@gmail.com - 2013-12-27 00:53 -0800
Re: Variables in a loop, Newby question Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-27 11:39 -0500
csiph-web