Python snippets

print formatting
print "server said %s and %s" % (content, txt)

delay / sleep
import time
time.sleep(30)

HTTP get / request
import httplib2
try:
resp, content = httplib2.Http().request("http://example.fi")
except urllib2.HTTPError, exc:
except urllib2.URLError, exc:
print "Failed because:", exc.reason

Send email
def sendMail(FROM,TO,SUBJECT,TEXT,SERVER):
import smtplib
"""this is some test documentation in the function"""
message = textwrap.dedent("""\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, TO, SUBJECT, TEXT))
# Send the mail
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()