Python Help function Debug function to get object properties and property values

Source: Internet
Author: User
Tags unsupported

Python Help function Debug function to get object properties and property values

Just in touch with Python, the first Python Web program, "Getting Started with Python," is very inconvenient to debug in a simple Web server, and does not know what properties the object has in detail, including what values, so it writes a function. Used to get the properties and property values of an object

The function code is as follows:

#调试函数. Properties and property values for output Object def getallattrs (obj): strattrs = ' for o in dir (obj): strattrs =strattrs + O + ': = ' + str (getattr (obj,o)) + ' <br/> ' return strattrs;
Detailed application code:

import os#python the OS module in the standard library includes universal operating system functionality from Basehttpserver import Httpserver, Basehttprequesthandler #导入HTTP处理相关的模块 # Debug function. Properties and property values for output Object def getallattrs (obj): strattrs = ' for o in dir (obj): strattrs =strattrs + O + ': = ' + str (getattr (obj,o)) + ' <br/> ' return strattrs; #自己定义处理程序.  For processing HTTP requests class Testhttphandler (Basehttprequesthandler): #处理GET请求 def do_get (self): #页面输出模板字符串 templatestr = "" 
the output is as follows:

MessageClass: = Mimetools. message__doc__: = none__init__: = >__module__: = __main__address_string: = >client_address: = (' 127.0.0.1 ', 38178) c Lose_connection: = 1command: = getconnection: = date_time_string: = >default_request_version: = Http/0.9disable_nagle _algorithm: = Falsedo_get: = >end_headers: = >error_content_type: = Text/htmlerror_message_format: =Error Responseerror code% d.message:% (Message) s.error code Explanation:% (code) s =% (explain) s. Finish: = >handle: = & Gt;handle_one_request: = >headers: = host:localhost:8000 connection:keep-alive pragma:no-cache cache-control:no-ca Che 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 ACC ept-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 ', ' June ', ' Jul ', ']parse_request ', ' Sep ', ' Oct ', ' Nov ', ' Dec ': = >path: =/protocal_version: = http/1. 1protocol_version: = http/1.0raw_requestline: = get/http/1.1 rbufsize: = -1request: = request_version: = HTTP/1.1request Line: = get/http/1.1responses: = {$: (' OK ', ' Request fulfilled, document follows '), 201: (' Created ', ' document Created , URL follows '), 202: (' Accepted ', ' Request Accepted, processing continues off-line '), 203: (' non-authoritative informatio n ', ' request fulfilled from the cache '), 204: (' No content ', ' request fulfilled, nothing follows '), 205: (' Reset Content ', ' Cl Ear input form for further input. '), 206: (' Partial content ', ' partial content follows '), +: (' Bad Request ', ' bad Reque St syntax or unsupported method '), 401: (' Unauthorized ', ' No permission--See authorization schemes '), 402: (' Payment Req Uired ', ' No payment--SEE charging schemes '), 403: (' Forbidden ', ' Request Forbidden--authorization would not help '), 404: (' Not Found ', ' nothing Matches the given URI '), 405: (' Method not allowed ', ' Specified method was invalid for this resource. '), 406: (' not Accept Able ', ' URI not available in preferred format. '), 407: (' Proxy authentication Required ', ' your must authenticate with this Proxy before proceeding. '), 408: (' request Timeout ', ' request timed out; try again later. '), 409: (' Conflict ', ' request Co Nflict. '), 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 La Rge ', ' 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: (' Expectati On Failed ', ' Expect condItion could not being satisfied. '),: (' Continue ', ' Request received, please Continue '), 101: (' Switching protocols ', ' SWI Tching to new Protocol; Obey Upgrade header '),: (' 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 Oth Er ', ' Object moved--see Method and URL List '), 304: (' Not Modified ', ' Document have not changed since given time '), 305: (' Use proxy ', ' Your must use proxy specified in the location to access this resource. '), 307: (' Temporary Redirect ', ' Object mo Ved temporarily--see URI List '), $: (' Internal server Error ', ' server got itself in trouble '), 501: (' not implemented ') , ' Server does not-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.3setup: = >sy S_version: = python/2.7.10timeout: = noneversion_string: = >wbufsize: = 0weekdayname: = [' Mon ', ' Tue ', ' Wed ', ' Thu ', ' F '  Ri ', ' Sat ', ' Sun ']wfile: =




Python Help function Debug function to get object properties and property values

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.