Problems with debugging Lists
Sancar Saran
sancar.saran at evodot.com
Fri Dec 11 17:11:38 EST 2009
Hello again.
I wrote small class for generating and accessing globalized Dictionary.
And of course I want to add some kind of debug ability to check what is
inside...
In php we had print_r function to see entire array structure. After some
search I found some equal module named pprint.
And some how this module wont work with mod_wsgi it was something about
mod_wsgi portability standards.
After some research there where some thing about putting some variables in
apache config to disable this.
And now I can see some dictionary structure in my apache log and I got some
errors like
r += pprint.pprint(self.data)
TypeError: cannot concatenate 'str' and 'NoneType' objects
So is there any way to get dictionary structure in string format ?
Another question is. When I import a module from top is it available for later
imported modules
# -*- coding: utf-8 -*-
import os, sys, cgi, pprint
import cgitb
cgitb.enable()
def application(environ, start_response):
sys.path.append(environ['DOCUMENT_ROOT']+"core")
#sys.path.append(environ['DOCUMENT_ROOT']+"util")
import registry, k5
#from print_r import print_r
# new registry
r = registry.Registry(environ)
r.set_entry('hede','hodo')
#response_headers = [('Content-type',k5.headers['content-type']+';
charset='+k5.headers['charset'])]
#start_response(kk5.headers['status'], response_headers)
# build the response body possibly using the environ dictionary
response_body = 'The request method was %s' % environ['REQUEST_METHOD']
response_body += '<br/>'
response_body += str(r.debug())
# HTTP response code and message
status = '200 OK'
# These are HTTP headers expected by the client.
# They must be wrapped as a list of tupled pairs:
# [(Header name, Header value)].
response_headers = [('Content-Type', 'text/plain'),
('Content-Length', str(len(response_body)))]
# Send them to the server using the supplied function
start_response(status, response_headers)
# Return the response body.
# Notice it is wrapped in a list although it could be any iterable.
return [response_body]
Following script was not working. I have to re import pprint from registry.
Is it normal or what is my problem :)
Regards
More information about the Python-list
mailing list