Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:Python': 0.05; 'context': 0.05; 'error:': 0.05; '__name__': 0.07; 'main()': 0.07; 'msg': 0.07; 'python': 0.09; '22,': 0.09; '__future__': 0.09; 'defined,': 0.09; 'msg)': 0.09; 'nameerror:': 0.09; 'output,': 0.09; 'spelled': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; 'dec': 0.15; 'sat,': 0.15; 'skip:f 30': 0.15; "'__main__':": 0.16; '2**20': 0.16; '36,': 0.16; 'alexander': 0.16; 'doesnt': 0.16; 'fromaddr': 0.16; 'isnt': 0.16; 'main():': 0.16; 'pipe,': 0.16; 'smtplib': 0.16; 'subprocess': 0.16; 'temp': 0.16; 'toaddrs': 0.16; 'wrote:': 0.17; 'typing': 0.17; 'memory': 0.18; 'import': 0.21; 'sends': 0.22; 'defined': 0.22; 'work.': 0.23; 'cc:2**1': 0.24; 'command': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; '(most': 0.27; 'cc:addr:gmail.com': 0.27; 'skip:# 10': 0.27; 'disk': 0.27; 'is?': 0.27; 'actual': 0.28; 'run': 0.28; 'post': 0.28; 'cpu': 0.29; 'credentials': 0.29; 'division': 0.29; 'url:mailman': 0.29; "skip:' 10": 0.30; 'checks': 0.30; 'error': 0.30; 'code': 0.31; 'december': 0.32; 'url:python': 0.32; 'file': 0.32; 'running': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'skip:s 30': 0.33; 'ram': 0.33; 'traceback': 0.33; 'anyone': 0.33; 'code:': 0.33; 'received:google.com': 0.34; 'server': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'wanted': 0.36; 'url:org': 0.36; 'totally': 0.36; 'should': 0.36; 'skip:p 20': 0.36; 'does': 0.37; 'two': 0.37; 'why': 0.37; 'virtual': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'gives': 0.39; 'skip:" 10': 0.40; 'url:mail': 0.40; 'subject:, ': 0.61; 'here': 0.65; 'want,': 0.65; 'email,': 0.66; 'cpu,': 0.84; 'temperature': 0.84; 'terrible': 0.84; 'joel': 0.91 Newsgroups: comp.lang.python Date: Sat, 22 Dec 2012 12:54:45 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=78.69.29.247; posting-account=wIPj3QoAAADyWSszXSDL7UajfW_9dhdN References: <543ec063-14c1-4ca6-a911-ae6f58c22a8c@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 78.69.29.247 MIME-Version: 1.0 Subject: Re: Python, email temperature From: KarlE To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: "python-list@python.org" , Alexander Ranstam 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: , Message-ID: Lines: 147 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356209693 news.xs4all.nl 6898 [2001:888:2000:d::a6]:51817 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35388 On Saturday, December 22, 2012 9:44:39 PM UTC+1, Joel Goldstick wrote: > On Sat, Dec 22, 2012 at 3:36 PM, Alexander Ranstam wro= te: >=20 > Hi! >=20 >=20 >=20 > Im totally new to Python, and im using it on my Raspberry pi. I found a p= rogram that sends an email, and one that checks the temperature of my CPU, = but i cant seem to combine the to into the funktion that i want, sending me= the CPU temp via Email. >=20 >=20 >=20 >=20 > The two programs work very well on their own, but this doesnt work. >=20 >=20 >=20 > this works: server.sendmail(fromaddr, toaddrs, msg) >=20 > but this doesnt: server.sendmail(fromaddr, toaddrs, cpu_temperature) >=20 >=20 >=20 > despite the command "print cputemp" working in the same program. >=20 >=20 >=20 > When i run the program i get the error: >=20 >=20 >=20 > Traceback (most recent call last): >=20 > =A0 File "sendcpu.py", line 36, in >=20 > =A0 =A0 msg =3D cpu_temperature >=20 > NameError: name 'cpu_temperature' is not defined >=20 >=20 >=20 > Does anyone know why the program claims that cpu_temperature isnt defined= , when it is? >=20 >=20 >=20 > You should copy and paste the code here including the context around the = error.=A0 You say print cputemp works, but cpu_temperature is not defined.= =A0 They are spelled differently.=A0 Start there=20 >=20 >=20 >=20 >=20 > Thanx! >=20 >=20 >=20 > //Alexander >=20 >=20 >=20 > -- >=20 > http://mail.python.org/mailman/listinfo/python-list >=20 >=20 >=20 >=20 > --=20 > Joel Goldstick Hi! I made a typing error, and couldnt edit the post :( this is the code: #!/usr/bin/env python from __future__ import division from subprocess import PIPE, Popen import psutil import smtplib def get_cpu_temperature(): process =3D Popen(['vcgencmd', 'measure_temp'], stdout=3DPIPE) output, _error =3D process.communicate() return float(output[output.index('=3D') + 1:output.rindex("'")]) def main(): cpu_temperature =3D get_cpu_temperature() cpu_usage =3D psutil.cpu_percent() ram =3D psutil.phymem_usage() ram_total =3D ram.total / 2**20 # MiB. ram_used =3D ram.used / 2**20 ram_free =3D ram.free / 2**20 ram_percent_used =3D ram.percent disk =3D psutil.disk_usage('/') disk_total =3D disk.total / 2**30 # GiB. disk_used =3D disk.used / 2**30 disk_free =3D disk.free / 2**30 disk_percent_used =3D disk.percent # # Print top five processes in terms of virtual memory usage. # print 'CPU temperature is: ', cpu_temperature fromaddr =3D 'myemailadress' toaddrs =3D 'myemailadress' #msg =3D 'There was a terrible error that occured and I wanted you to know!= ' msg =3D cpu_temperature # Credentials (if needed) username =3D 'myusername' password =3D 'mypassword' # The actual mail send server =3D smtplib.SMTP('smtp.gmail.com:587') server.starttls() server.login(username,password) server.sendmail(fromaddr, toaddrs, cpu_temperature) server.quit() if __name__ =3D=3D '__main__': main() running it gives the following error: pi@raspberrypi /home/python $ python sendcpu.py Traceback (most recent call last): File "sendcpu.py", line 36, in msg =3D cpu_temperature NameError: name 'cpu_temperature' is not defined pi@raspberrypi /home/python $ isnt cpu_temperature defined?