Python重新加载模块
from imp import reload reload(模块名)#重新载入模块,前提是模块已经导入
Python socket实现简单web服务器
import socket def service_client(new_socket): try: request = new_socket.recv(1024) print(request) response = "HTTP/1.1 200 OK " response += " " response += "<p1>tcp_socket</p1>" new_socket.send(response.encode("utf-8")) new_socket.close() except: new_socket.close() def main(): tcp_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) tcp_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1) tcp_socket.bind(("",80)) tcp_socket.listen(128) while True: new_socket,client_add = tcp_socket.accept() service_client(new_socket) tcp_socket.close() if __name__ == '__main__': main()