[mod_python] Form upload

Terry Macdonald terry.macdonald at dsl.pipex.com
Fri May 19 07:38:45 EDT 2006


Graham Dumpleton wrote:
>
> On 19/05/2006, at 8:13 PM, Terry Macdonald wrote:
>
>>
>> "sys.stdout=sys.stderr=req"
>>
>> This may be a dumb question but I'm not getting it...
>> What does the above line do?
>> Why does one want to set standard error and standard out to the 
>> request object?
>> What does printing to the request object do?
>> ...and how does it work?
>>
>> I'm missing something fundamentally object oriented here, aren't I?
>>
>> I just see objects that are used to print stuff and then a request 
>> object which contains request information. I'm not getting the link.
>
> Both sys.stderr and sys.stdout are file objects. The primary method 
> for writing
> data is the "write()" member function. It is the "write()" member 
> function that "print"
> calls on the sys.stdout file object.
>
> Outside of mod_python, you could replace sys.stdout with some other 
> file object,
> for example an open log file, and every use of "print" in the program 
> would see that
> output go to the log file instead.
>
> In practice, sys.stdout doesn't actually have to be a file object, 
> just a file like
> object which provides a "write()" method. As a "req" object provides a 
> "write()"
> function, it could technically thus be used as a substitute for 
> sys.stdout. As I
> pointed out in prior email though, this would actually be a dangerous 
> thing
> to do in mod_python where a multithreaded MPM is being used.
>
> Hope this makes sense.
>
> Graham
Thanks for the help/reply Graham

So effectively if you print something to the req object it morphs into a 
response back to the client browser?




More information about the Mod_python mailing list