python的函数的对象属性_Python帮助函数调试函数 用于获取对象的属性及属性值...
Python帮助函数调试函数 用于获取对象的属性及属性值
刚接触Python,上篇 《Python入门》第一个Python Web程序——简单的Web服务器 中调试非常不方便,不知道对象详细有什么属性,包括什么值,所以写了一个函数。用于获取对象的属性及属性值
函数代码例如以下:
#调试函数。用于输出对象的属性及属性值
def getAllAttrs(obj):
strAttrs = ‘‘
for o in dir(obj):
strAttrs =strAttrs + o + ‘ := ‘ + str(getattr(obj,o)) + ‘
‘
return strAttrs;详细应用代码:
import os#Python的标准库中的os模块包括普遍的操作系统功能
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler #导入HTTP处理相关的模块
#调试函数。用于输出对象的属性及属性值
def getAllAttrs(obj):
strAttrs = ‘‘
for o in dir(obj):
strAttrs =strAttrs + o + ‘ := ‘ + str(getattr(obj,o)) + ‘
‘
return strAttrs;
#自己定义处理程序。用于处理HTTP请求
class TestHTTPHandler(BaseHTTPRequestHandler):
#处理GET请求
def do_GET(self):
#页面输出模板字符串
templateStr = ‘‘‘
QR Link Generator
%s
‘‘‘
self.protocal_version = ‘HTTP/1.1‘#设置协议版本号
self.send_response(200)#设置响应状态码
self.send_header("Welcome", "Contect")#设置响应头
self.end_headers()
self.wfile.write(templateStr % getAllAttrs(self))#输出响应内容
#启动服务函数
def start_server(port):
http_server = HTTPServer((‘‘, int(port)), TestHTTPHandler)
http_server.serve_forever()#设置一直监听并接收请求
os.chdir(‘static‘)#改变工作文件夹到 static 文件夹
start_server(8000)#启动服务。监听8000端口输出例如以下:
MessageClass := mimetools.Message
__doc__ := None
__init__ := >
__module__ := __main__
address_string := >
client_address := (‘127.0.0.1‘, 38178)
close_connection := 1
command := GET
connection :=
date_time_string := >
default_request_version := HTTP/0.9
disable_nagle_algorithm := False
do_GET := >
end_headers := >
error_content_type := text/html
error_message_format :=
Error response
Error code %(code)d.
Message: %(message)s.
Error code explanation: %(code)s = %(explain)s.
finish := >
handle := >
handle_one_request := >
headers := Host: localhost:8000 Connection: keep-alive Pragma: no-cache Cache-Control: no-cache Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36 Accept-Encoding: gzip, deflate, sdch Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4,en-GB;q=0.2 Cookie: bdshare_firstime=1451130349627
log_date_time_string := >
log_error := >
log_message := >
log_request := >
monthname := [None, ‘Jan‘, ‘Feb‘, ‘Mar‘, ‘Apr‘, ‘May‘, ‘Jun‘, ‘Jul‘, ‘Aug‘, ‘Sep‘, ‘Oct‘, ‘Nov‘, ‘Dec‘]
parse_request := >
path := /
protocal_version := HTTP/1.1
protocol_version := HTTP/1.0
raw_requestline := GET / HTTP/1.1
rbufsize := -1
request :=
request_version := HTTP/1.1
requestline := GET / HTTP/1.1
responses := {200: (‘OK‘, ‘Request fulfilled, document follows‘), 201: (‘Created‘, ‘Document created, URL follows‘), 202: (‘Accepted‘, ‘Request accepted, processing continues off-line‘), 203: (‘Non-Authoritative Information‘, ‘Request fulfilled from cache‘), 204: (‘No Content‘, ‘Request fulfilled, nothing follows‘), 205: (‘Reset Content‘, ‘Clear input form for further input.‘), 206: (‘Partial Content‘, ‘Partial content follows.‘), 400: (‘Bad Request‘, ‘Bad request syntax or unsupported method‘), 401: (‘Unauthorized‘, ‘No permission -- see authorization schemes‘), 402: (‘Payment Required‘, ‘No payment -- see charging schemes‘), 403: (‘Forbidden‘, ‘Request forbidden -- authorization will not help‘), 404: (‘Not Found‘, ‘Nothing matches the given URI‘), 405: (‘Method Not Allowed‘, ‘Specified method is invalid for this resource.‘), 406: (‘Not Acceptable‘, ‘URI not available in preferred format.‘), 407: (‘Proxy Authentication Required‘, ‘You must authenticate with this proxy before proceeding.‘), 408: (‘Request Timeout‘, ‘Request timed out; try again later.‘), 409: (‘Conflict‘, ‘Request conflict.‘), 410: (‘Gone‘, ‘URI no longer exists and has been permanently removed.‘), 411: (‘Length Required‘, ‘Client must specify Content-Length.‘), 412: (‘Precondition Failed‘, ‘Precondition in headers is false.‘), 413: (‘Request Entity Too Large‘, ‘Entity is too large.‘), 414: (‘Request-URI Too Long‘, ‘URI is too long.‘), 415: (‘Unsupported Media Type‘, ‘Entity body in unsupported format.‘), 416: (‘Requested Range Not Satisfiable‘, ‘Cannot satisfy request range.‘), 417: (‘Expectation Failed‘, ‘Expect condition could not be satisfied.‘), 100: (‘Continue‘, ‘Request received, please continue‘), 101: (‘Switching Protocols‘, ‘Switching to new protocol; obey Upgrade header‘), 300: (‘Multiple Choices‘, ‘Object has several resources -- see URI list‘), 301: (‘Moved Permanently‘, ‘Object moved permanently -- see URI list‘), 302: (‘Found‘, ‘Object moved temporarily -- see URI list‘), 303: (‘See Other‘, ‘Object moved -- see Method and URL list‘), 304: (‘Not Modified‘, ‘Document has not changed since given time‘), 305: (‘Use Proxy‘, ‘You must use proxy specified in Location to access this resource.‘), 307: (‘Temporary Redirect‘, ‘Object moved temporarily -- see URI list‘), 500: (‘Internal Server Error‘, ‘Server got itself in trouble‘), 501: (‘Not Implemented‘, ‘Server does not support this operation‘), 502: (‘Bad Gateway‘, ‘Invalid responses from another server/proxy.‘), 503: (‘Service Unavailable‘, ‘The server cannot process the request due to a high load‘), 504: (‘Gateway Timeout‘, ‘The gateway server did not receive a timely response‘), 505: (‘HTTP Version Not Supported‘, ‘Cannot fulfill request.‘)}
rfile :=
send_error := >
send_header := >
send_response := >
server :=
server_version := BaseHTTP/0.3
setup := >
sys_version := Python/2.7.10
timeout := None
version_string := >
wbufsize := 0
weekdayname := [‘Mon‘, ‘Tue‘, ‘Wed‘, ‘Thu‘, ‘Fri‘, ‘Sat‘, ‘Sun‘]
wfile :=
python的函数的对象属性_Python帮助函数调试函数 用于获取对象的属性及属性值...相关推荐
- 可以获取python中输出函数帮助的是_Python帮助函数调试函数 用于获取对象的属性及属性值...
Python帮助函数调试函数 用于获取对象的属性及属性值 刚接触Python,上篇 <Python入门>第一个Python Web程序--简单的Web服务器 中调试非常不方便,不知道对象详 ...
- JAVA中所有对象的超类是_在Java中获取对象的超类
可以使用java.lang.Class.getSuperclass()方法获得任何实体的直接超类,例如对象,类,原始类型,接口等.此方法不包含任何参数. 演示此的程序如下所示- 示例public cl ...
- python函数作用域与闭包_python基础-08-内置函数、作用域、闭包、递归
python基础-内置函数.作用域.闭包.递归 1.常见的内置函数 常见的内置函数: 查看内置函数: print(dir(__builtins__)) 常见函数 type() 数据类型 print() ...
- python 魔法函数是什么意思_Python 中的魔法函数
魔法函数是Python中的特性,学习好魔法函数将有助于我们写出优秀的pythonic(优雅的.地道的.整洁的)代码,同时因为Python语言的特性,我们在进行框架设计的时候除了设计模式等高级技能,魔法 ...
- python函数速查手册_Python进阶-内置函数大全
#1.abs() 绝对值或复数的模abs(-1) >>> 1 #2.all() 接受一个迭代器,如果迭代器的所有元素都为真,那么返回True,否则返回Falseall([1,2,3] ...
- python函数的基础知识_Python入门基础知识点(函数进阶)
动态参数: 动态接收位置参数: def eat(*args): #在形参位置,*叫做聚合 print('我想吃',args) eat('大米饭','中米饭','小米饭') #收到的结果是一个tuple ...
- python函数名的语法_Python 基础语法六 ——函数
一个程序可以按不同的功能实现拆分成不同的模块,而函数就是能实现某一部分功能的代码块. 1.函数的概述 定义:在Python中,定义个函数要使用 def 语句,一次写出函数名.括号.括号中的参数和冒号( ...
- 在python子程序中、使用关键字_Python 的控制和函数
控制if else for while 函数 函数的定义 函数一词来源于数学,但编程中的函数概念,与数学中的函数是有很大不同的,具体区别,我们后面会讲,编程中的函数在英文中也有很多不同的叫法.在BAS ...
- python函数大全和意思_python 之 内置函数大全
一.罗列全部的内置函数 二.range.xrange(迭代器) 无论是range()还是xrange()都是Python里的内置函数.这个两个内置函数最常用在for循环中.例如: >>&g ...
最新文章
- 深度学习《CNN架构续篇 - 1乘1卷积》
- 七月老师python_七月在线Python学习笔记
- SqlServer实现split功能
- linux下安装redis 3.2.1
- C语言写学生成绩管理系统(超详细注解)
- 转:MediaCoder H.264格式编码参数设置及详解
- 深度linux wubildr.mbr,把玩Linux何须安装
- python 自相关_自相关与偏自相关的简单介绍
- trados 有道api_在Trados中使用微软机器翻译
- Github 汉化插件教程
- Python 发送短信
- 我对顶级域名、一级域名和二级域名的认识
- 【科学数据库】数据的合并与分组聚合||||||||
- 《国史通鉴》- 宋朝
- 3dmax最全选择方式讲解
- java 读取Excel
- [ShaderGraph]11.小草摇曳效果
- 【雕刻机】grbl control软件设置
- AXURE原型:AI翻译平台
- 苹果商城怎么调成中文_不会PR怎么做视频剪辑?这三个网站就能帮你轻松搞定...