用到的模块学习心得
时间:2009-04-08 来源:hkebao
1.BaseHTTPServer
这个模块定义了两个类用来实现 HTTP 服务器(WEB服务器)。通常本模块不会直接使用
第一个类,HTTPServer 是一个 SocketServer.TCPServer 的子集。他创建并监听 HTTP 套接字,分配 requests 到处理器(handler)。编码创建并运行这个服务器看起来像这样:
This class is used to handle the HTTP requests that arrive at the server. By itself, it cannot respond to any actual HTTP requests; it must be subclassed to handle each request method (e.g. GET or POST). BaseHTTPRequestHandler provides a number of class and instance variables, and methods for use by subclasses. 这个类的功能就是:处理来自于客户端的请求操作。包括GET或POST的操作的!本身是不能正确地进行处理请求操作的。必须要通过其子类进行重写它!struct的功能:This can be used in handling binary data stored in files or from network connections, among other sources.
This module performs conversions between Python values and C structs represented as Python strings.
<title>4.3 struct -- Interpret strings as packed binary data</title><link href="lib.css" type="text/css" rel="STYLESHEET"><link href="../icons/pyfav.png" type="image/png" rel="SHORTCUT ICON"><link title="Python documentation Index" href="../index.html" rel="start"><link title="Python library Reference" href="lib.html" rel="first"><link title="Contents" href="contents.html" rel="contents"><link title="Index" href="genindex.html" rel="index"><link title="About this document..." href="about.html" rel="last"><link title="About this document..." href="about.html" rel="help"><link href="module-difflib.html" rel="next"><link href="module-re.html" rel="prev"><link href="strings.html" rel="parent"><link href="struct-objects.html" rel="next">
Return a string containing the values v1, v2, ... packed according to the given format. The arguments must match the values required by the format exactly. 1.OS模块
<title>14.1 os -- Miscellaneous operating system interfaces</title><link href="lib.css" type="text/css" rel="STYLESHEET"><link href="../icons/pyfav.png" type="image/png" rel="SHORTCUT ICON"><link title="Python documentation Index" href="../index.html" rel="start"><link title="Python library Reference" href="lib.html" rel="first"><link title="Contents" href="contents.html" rel="contents"><link title="Index" href="genindex.html" rel="index"><link title="About this document..." href="about.html" rel="last"><link title="About this document..." href="about.html" rel="help"><link href="module-time.html" rel="next"><link href="allos.html" rel="prev"><link href="allos.html" rel="parent"><link href="os-procinfo.html" rel="next">name The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'. 例如:print os.name 打印出来 nt
这个模块定义了两个类用来实现 HTTP 服务器(WEB服务器)。通常本模块不会直接使用
第一个类,HTTPServer 是一个 SocketServer.TCPServer 的子集。他创建并监听 HTTP 套接字,分配 requests 到处理器(handler)。编码创建并运行这个服务器看起来像这样:
def run(server_class=BaseHTTPServer.HTTPServer,
handler_class=BaseHTTPServer.BaseHTTPRequestHandler):
server_address = (”, 8000)
httpd = server_class(server_address, handler_class)
httpd.serve_forever()
这个类在 HTTP 请求到达时处理它。实际上它自身并不能对任何 HTTP 请求作出响应,他必须存在派生类用来处理每一个请求方法(例如 GET 或者 POST)。BaseHTTPRequestHandler 为子集提供许多类变量、实例变量和方法。
《通过派生类去处理来自客户端的POST与GET请求的》
class BaseHTTPRequestHandler( | request, client_address, server) |
This module performs conversions between Python values and C structs represented as Python strings.
<title>4.3 struct -- Interpret strings as packed binary data</title><link href="lib.css" type="text/css" rel="STYLESHEET"><link href="../icons/pyfav.png" type="image/png" rel="SHORTCUT ICON"><link title="Python documentation Index" href="../index.html" rel="start"><link title="Python library Reference" href="lib.html" rel="first"><link title="Contents" href="contents.html" rel="contents"><link title="Index" href="genindex.html" rel="index"><link title="About this document..." href="about.html" rel="last"><link title="About this document..." href="about.html" rel="help"><link href="module-difflib.html" rel="next"><link href="module-re.html" rel="prev"><link href="strings.html" rel="parent"><link href="struct-objects.html" rel="next">
pack( | fmt, v1, v2, ...) |
<title>14.1 os -- Miscellaneous operating system interfaces</title><link href="lib.css" type="text/css" rel="STYLESHEET"><link href="../icons/pyfav.png" type="image/png" rel="SHORTCUT ICON"><link title="Python documentation Index" href="../index.html" rel="start"><link title="Python library Reference" href="lib.html" rel="first"><link title="Contents" href="contents.html" rel="contents"><link title="Index" href="genindex.html" rel="index"><link title="About this document..." href="about.html" rel="last"><link title="About this document..." href="about.html" rel="help"><link href="module-time.html" rel="next"><link href="allos.html" rel="prev"><link href="allos.html" rel="parent"><link href="os-procinfo.html" rel="next">name The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'. 例如:print os.name 打印出来 nt
相关阅读 更多 +