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帮助函数调试函数 用于获取对象的属性及属性值...相关推荐

  1. python中area是什么意思_python中none表示什么

    Q1:python里None 表示False吗 通常不这样表达.因为在python里定义find如果不为0和正数就是没有找到.并不一定是-1 一般是这样写if s.find("a" ...

  2. python中matplotlib自定义设置图像标题使用的字体类型:获取默认的字体族及字体族中对应的字体、自定义设置图像标题使用的字体类型

    python中matplotlib自定义设置图像标题使用的字体类型:获取默认的字体族及字体族中对应的字体.自定义设置图像标题使用的字体类型 目录

  3. 获取Python中的所有对象属性?

    本文翻译自:Get all object attributes in Python? Is there a way to get all attributes/methods/fields/etc. ...

  4. python中迭代器的实现原理_Python 进阶应用教程

    Python 中的迭代器实现原理 在数学中,集合表示由一个或多个确定的元素所构成的整体.在 Python 中,列表.元组.集合可以用于表示数学中的集合. 例如,分别使用列表.元组.集合表示了一个包含 ...

  5. python中对文件、文件夹(文件操作函数)的操作

    python中对文件.文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块. 得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 返回指定目录下的所有文件和目 ...

  6. python的函数的对象属性_Python帮助函数调试函数 用于获取对象的属性及属性值...

    Python帮助函数调试函数 用于获取对象的属性及属性值 刚接触Python,上篇 <Python入门>第一个Python Web程序--简单的Web服务器 中调试非常不方便,不知道对象详 ...

  7. Python中的 len() 是什么?如何使用 len() 函数查找字符串的长度

    Python中的 len() 是什么?如何使用 len() 函数查找字符串的长度 在编程语言中,获取特定数据类型的长度是一种常见做法. Python也一样,因为可以使用内置的 len() 函数来获取字 ...

  8. python中forward是什么意思_Python 中 fd 表示什么?

    以下是即将出版的一本书中的草稿,尚待完善,先发在这里权当回答. -------------------------------- 在Python中可以通过编码实现对文件的读写操作,然而必须清楚的是,程 ...

  9. python中的counter()、elements()、most_common()和subtract()函数的用法

    python中的counter().elements().most_common()和subtract()函数的用法 counter()方法: class collections.Counter([i ...

最新文章

  1. go的异常处理,defer,panic,recover
  2. 关于升级 xcode8
  3. 下拉菜单实现树状结构_二叉索引树(树状数组)的原理
  4. DjangoORM字段介绍
  5. Express与传统Web应用(服务端渲染、art-template模板引擎、配置静态资源托管)
  6. Linux Malloc分析-从用户空间到内核空间【转】
  7. 【VRP】基于matlab改进的模拟退火和遗传算法求解车辆路径规划问题【含Matlab源码 343期】
  8. 在Ubuntu系统下进行引导修复
  9. 计算机固态硬盘安装,台式计算机的固态硬盘安装方法和步骤教程
  10. mysql富文本_mysql模糊查询富文本的文本内容
  11. Eclipse中安装反编译工具Fernflower(Enhanced Class Decompiler)
  12. 2017 华为软件精英挑战赛
  13. spark sample采样
  14. 海量数据等概率选取问题
  15. Qt 之 打开exe程序
  16. android 友盟统计功能,在Android工程中集成友盟统计
  17. 「微信群合影2.3.0」- 新增高清头像
  18. 高校新闻抓取分析之百度新闻篇---数据抓取
  19. 常见的希腊字母及读音
  20. 计算油费 (10 分)

热门文章

  1. Microbiome:马铃薯疮痂病与土壤微生物组关系新进展
  2. Cell子刊:根瘤菌微生物群落的模块化特征及其与共生根瘤菌的进化关系
  3. R语言使用caret包构建遗传算法树模型(Tree Models from Genetic Algorithms )构建回归模型、通过method参数指定算法名称
  4. R语言使用magick包的image_annotate函数在图片中添加文本标签信息、自定义文本标签内容的位置、色彩(Text annotations)
  5. R语言进行dataframe数据左连接(Left join):使用R原生方法、data.table、dplyr等方案
  6. R语言dplyr包distinct函数去除重复数据行实战
  7. 基于网格的聚类算法STING
  8. 基于Keras Application和Densenet迁移学习(transfer learning)的乳腺癌图像分类模型(良性、恶性)
  9. ML基石_8_NoiseAndError
  10. 工具_SublimeText