Python知识点
Posted xlcm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python知识点相关的知识,希望对你有一定的参考价值。
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\r\n" response += "\r\n" 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()
以上是关于Python知识点的主要内容,如果未能解决你的问题,请参考以下文章