Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script for serving static files from the current directory. Very handy.
#!/usr/bin/env python
import SimpleHTTPServer
import SocketServer
from argparse import ArgumentParser
import socket
parser = ArgumentParser(
description='Serve static files in the current directory.')
parser.add_argument('--port', default=8000, dest='port',
type=int, help='The port number to be used')
args = parser.parse_args()
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
try:
httpd = SocketServer.TCPServer(("", args.port), Handler)
print 'Serving at http://localhost:%d' % args.port
httpd.serve_forever()
except socket.error:
print 'Port %d is already in use.' % args.port, \
'You may try a different port by using the --port flag.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment