[mod_python] psp prints

Graham Dumpleton grahamd at dscpl.com.au
Wed Mar 8 05:49:05 EST 2006

On 08/03/2006, at 9:41 PM, Peter Sheldrick wrote:

> If i do it like that, i get the unambigous error: "NameError: global 
> name 'req' is not defined". I have imported a module into my psp page 
> - those functions gerate html. These functions don't know about the 
> page variable req. So is the best way to pass req to all the functions 
> i want to call (and that want to print)?. Is this just a missuse and 
> psp should be self contained; this means: only use functions defined 
> within the psp page?

Passing "req" to functions called from the PSP page is fine
and would be necessary in a lot of cases.

Maybe some others on the mailing list who use PSP on a regular
basis might give suggestions on how to best structure stuff,
but in general it is possibly better to have as little Python
code in the actual PSP page as possible, with it all being
separated into separate functions. That way the PSP page is
cleaner and code is reusable across multiple pages.

PS, please remember to use reply-all so messages go back to
the mailing list.


> On 3/8/06, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
>> On 08/03/2006, at 9:19 PM, Peter Sheldrick wrote:
>> > With psp you can gereate html by doing <%= "html" %> or def fun:
>> > return "html" <%= fun() %> is there a way for fun to just "print" 
>> the
>> > html? For example when it is called by a few functions first i don't
>> > want to have to pass the return string of fun() to all above
>> > functions.
>> You can still call req.write().
>> <%=
>>  req.write("html")
>> %>
>> Is that what you want?
>> Graham

More information about the Mod_python mailing list