[mod_python] Tips and Tricks initiative ... some followup contribution /3

Dustin Mitchell dustin at ywlcs.org
Wed Jul 3 16:01:39 EST 2002


On Wed, Jul 03, 2002 at 04:37:49PM -0500, vio wrote:
> Already reaching the bottom of my mod_python tricks basket:
> 
> 
> REQUEST Attributes Made Easy
> 
> Description:
>   How can I see all REQUEST's attributes in one swoop.
> 
> Solution:
>   (one amongst many, I believe)
> 
>   def handler(REQUEST):
>       # set headers
>       REQUEST.content_type = "text/html"
>       REQUEST.send_http_header()
> 
>       # list all REQUEST's attributes
>       REQUEST.write('<HTML><BODY>\n\n')
>       for item in dir(REQUEST):
>               exec('x = REQUEST.' + str(item))
>               REQUEST.write('REQUEST.' + str(item) + ' = ' + str(x))
>               REQUEST.write('\n\n<BR>\n\n')
 let's avoid 'exec'; how about
                x = getattr(REQUEST, item)
                REQUEST.write('REQUEST.%s = %s\n\n<br>\n\n' % item, `x`)
> 
>       REQUEST.write('\n\n</BODY></HTML>\n')
>       return apache.OK

-- 

  Dustin Mitchell
  dustin at ywlcs.org
  http://people.cs.uchicago.edu/~dustin/



More information about the Mod_python mailing list