Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62731
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <torriem+gmail@torriefamily.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.043 |
| X-Spam-Evidence | '*H*': 0.92; '*S*': 0.00; 'tutorials,': 0.09; 'subject:question': 0.10; 'python': 0.11; 'def': 0.12; 'posted': 0.15; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'scripts.': 0.16; 'stuff.': 0.16; 'temperatures': 0.16; 'track.': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'programming': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'gives': 0.31; 'code': 0.31; 'text': 0.33; 'open': 0.33; 'skip:_ 10': 0.34; 'could': 0.34; 'but': 0.35; 'should': 0.36; 'list': 0.37; 'skip:o 20': 0.38; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'structure': 0.39; 'use.': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'read': 0.60; 'hope': 0.61; 'skip:t 30': 0.61; "you'll": 0.62; 'email addr:gmail.com': 0.63; 'skip:+ 10': 0.65; 'online': 0.71; 'temperature': 0.84; 'temps': 0.84; 'vba': 0.84 |
| X-Virus-Scanned | amavisd-new at torriefamily.org |
| Date | Wed, 25 Dec 2013 23:34:13 -0700 |
| From | Michael Torrie <torriem@gmail.com> |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:10.0.12) Gecko/20130105 Thunderbird/10.0.12 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Variables in a loop, Newby question |
| References | <9ad01eef-baf0-4018-833e-0b4dce4b9b85@googlegroups.com> <c13e6d17-1703-41f7-81ed-65d9d8b4c259@googlegroups.com> |
| In-Reply-To | <c13e6d17-1703-41f7-81ed-65d9d8b4c259@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4626.1388041482.18130.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1388041482 news.xs4all.nl 2970 [2001:888:2000:d::a6]:43830 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:62731 |
Show key headers only | View raw
On 12/24/2013 11:27 AM, vanommen.robert@gmail.com wrote:
> Indeed this is code what I found on the web to read temperatures from
> 10 DS18B20 singlewire sensors.
>
> My only programming (little) experience is VBA (Excel mostly).
>
Definitely you'll want to learn python before you go much farther in
this project. Check out the online docs, tutorials, etc.
> In this script i want to read the temperatures and make them
> available to other scripts.
Here's some almost runnable code that might help you get down the right
track. You'll have to fill in some of the stuff.
temperatures.py:
import time
sensorids = [...] #fill in these with your ids
def _read_sensor(id):
# open /sys/bus/w1/deevices/id/slave
text = ''
while text.split("\n")[0].find("YES") == -1:
tfile = open("/sys/bus/w1/devices/"+ id +"/w1_slave")
text = tfile.read()
tfile.close()
time.sleep(0.1)
temperaturedata = text.split("\n")[1].split(" ")[9]it(" ")[9]
temperature = float(temperaturedata [2:]) / 1000
return temperature
def get_temperatures():
# not using list comprehensions but we could
temps = []
for sensor in sensorids:
temps.append(_read_sensor(sensor))
Then in your other python modules (scripts):
import temperatures
print temperatures.get_temperatures() # should print a list
Hope this gives you a bit of structure you can use. All the code you
need to fill in can come from the code you posted previously.
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