[mod_python] Capturing PSP output

Graham Dumpleton grahamd at dscpl.com.au
Mon May 30 18:37:30 EDT 2005

On 31/05/2005, at 2:19 AM, Joshua Ginsberg wrote:

> Hello --
> I'm trying to do something a little unorthodox... I didn't know if 
> anybody had tried it before... Within a PSP page, I want to run 
> another PSP page and capture the output to a string.
> To do a little testing, I wrote the following PSP page:
> <%
> def sAppend(self, thestring):
>     if '__s__' not in dir(self):
>         self.__s__ = ''
>     self.__s__ += str(thestring)
> oldReqWrite = req.write
> req.write = sAppend

This is a bit confusing. Your method accepts a "self" parameter as if 
it is a
method of a class when it isn't. Just because you replace an existing 
method will not turn your one into one.

The result is that the string to be output is being passed as self and 
doesn't have a "__s__" member.

There are other problems with using "__s__" as well but rather than go 
into it,
you should just look at:


That code could probably still be cleaned up a bit perhaps as certain 
don't need to be done, also not sure why other things are being done 
If I get a chance later I'll see if I can come up with a more 

BTW, did you want to actually reference the original "req" object for 
data. The example referenced obviously doesn't allow this as it 
replaces the "req" object with a StringIO object.


More information about the Mod_python mailing list