simple python web sever
- User
simple python web sever
Assistant
Here's a simple Python web server using the built-in
http.servermodule:from http.server import HTTPServer, SimpleHTTPRequestHandler import socket # Set host and port host = 'localhost' port = 8000 # Create server server = HTTPServer((host, port), SimpleHTTPRequestHandler) print(f"Server running at http://{host}:{port}") # Start server try: server.serve_forever() except KeyboardInterrupt: print("\nShutting down server...") server.server_close()To use this:
- Save it to a file (e.g.
server.py) - Run it from the terminal:
python server.py - The server will serve files from the current directory
- Access it in your browser at
http://localhost:8000 - Press Ctrl+C to stop the server
For an even simpler one-liner, you can also just run this command in your terminal:
python -m http.server 8000- Save it to a file (e.g.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.