Damjan wrote: > This is a simplification of the program > > c = db.cursor() > while 1: > c.execute('select ....') > smtp = SMTP(MAIL_HOST, 25, 'localhost') > for address, subject, body in c: > smtp.sendmail(....) > smtp.quit() > time.sleep(60) > > now if the select doesn't return any rows, there's no need to connect to the > mail server. I'd like to avoid that unnecessary step. [...]
Well, something like: c = db.cursor() while 1: smtp = None c.execute('select ....') for address, subject, body in c: if not smtp: smtp = SMTP(MAIL_HOST, 25, 'localhost') smtp.sendmail(....) if smtp: smtp.quit() time.sleep(60) should do that. -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list