Python for the new year

I’d looked at but then avoided Python because it wasn’t a real programming language. No curly braces. No semicolons.

But intrigued by this minimalist web server:

PORT = 9914
import SimpleHTTPServer
import BaseHTTPServer
import SocketServer

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

class Server(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):

httpd = Server((SERVER, PORT), Handler)
print "Web Server listening on http://%s:%s/ (stop with ctrl+c)…" % (SERVER, PORT)

except KeyboardInterrupt:
    print "Going down…"

included in the processing.js examples I took another look.

Here’s a quick script to calculate a hash of The Guardian’s home page (as a simple crude way to see if it changed):

import urllib
import hashlib

pageURL = ""
f = urllib.urlopen(pageURL)
pageContent =

m = hashlib.md5()
value = m.hexdigest()
print value

The best bit? Curley braces:

pagesDict = {pageURL:  value}

Going to dig some more and experiment with a view to using in the classroom alongside some C# and JavaScript we’re already using.

Recommended reading: the Python edition of How to think like a Computer Scientist. Oh, and Spike had a poem about it. Something about being curled around a tree and eaten.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>