#! /usr/local/bin/python3 from http.server import HTTPServer, SimpleHTTPRequestHandler, BaseHTTPRequestHandler import sys def start_server(server_class = HTTPServer, handler_class = SimpleHTTPRequestHandler): port = 9099 server_address = ('',port) httpd = server_class(server_address, handler_class) try: print("Serving at port: " + str(port) + ".") httpd.serve_forever() except KeyboardInterrupt: print("\nStopping server.") httpd.server_close() sys.exit(0) start_server()
- Name your classes and functions consistently; the convention is:
- to use
CamelCasefor classes and
lower_case_with_underscoresfor functions and methods.
- Always use
selfas the name for the first method argument.
- to use
Use spaces around operators and after commas, but not directly inside bracketing constructs:
a = f(1, 2) + g(3, 4).
Use 4-space indentation, and no tabs.
4 spaces are a good compromise between small indentation (allows greater nesting depth) and large indentation (easier to read). Tabs introduce confusion, and are best left out.
Wrap lines so that they don’t exceed 79 characters.
This helps users with small displays and makes it possible to have several code files side-by-side on larger displays.
Use blank lines to separate functions and classes, and larger blocks of code inside functions.
When possible, put comments on a line of their own.
Don’t use fancy encodings if your code is meant to be used in international environments. Plain ASCII works best in any case.
Excellent resource: https://google.github.io/styleguide/pyguide.html
A really interesting TED talk.