On 02/11/14 23:55, Kody Fergerson wrote:

worried about you all having it. When I try to check it or run it it
comes up with "invalid syntax" and highlights the first "@" symbol. The
code is as follows...

TO = kody.was...@gmail.com <mailto:kody.was...@gmail.com>
GMAIL_USER = kody.was...@gmail.com <mailto:kody.was...@gmail.com>
GMAIL_PASS = shed no tears

These values are all strings so need to be enclosed in quote signs.
Python is trying to evaluate them as code and the @ makes no sense.


SUBJECT = 'Intrusion!!'
TEXT = 'Your PIR sensor detected movement'

You got it right here.

ser = serial.Serial('COM4', 9600)

def send_email():
     print("Sending Email")
     smtpserver = smtplib.SMTP("smtp.gmail.com <http://smtp.gmail.com>",587)
     smtpserver.ehlo()
     smtpserver.starttls()
     smtpserver.ehlo
     smtpserver.login(GMAIL_USER, GMAIL_PASS)
     header = 'To:' + TO + '\n' + 'From: ' + GMAIL_USER
     header = header + '\n' + 'Subject:' + SUBJECT + '\n'
     print header
     msg = header + '\n' + TEXT + ' \n\n'
     smtpserver.sendmail(GMAIL_USER, TO, msg)
     smtpserver.close()

Its traditional to have a blank line after a function definition.
It just makes it clearer where the definition ends.

while True:
     message = ser.readline()
     print(message)
     if message[0] == 'M' :
         send_email(

Something missing there?

     time.sleep(0.5)


HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to