[mod_python] psp problem

Jim Gallacher jg.lists at sympatico.ca
Thu May 12 11:15:01 EDT 2005


Wouter van Marle wrote:
> On Wed, 2005-05-11 at 23:49 -0400, Gregory (Grisha) Trubetskoy wrote:
> 
>>On Wed, 11 May 2005, Jim Gallacher wrote:
>>
>>
>>>You found one of the warts in psp. Since your for loop contains no further 
>>>python statements, the parser gets confused. Try adding a single comment at 
>>>the beginning of your for loop:
>>>
>>><p> some text for the page </p>
>>><%
>>>for r in Results:
>>>   # begin indentation - comment fixes the syntax error
>>>%>
>>>I got the result <%=r%><br>
>>><%
>>># end indentation
>>>%>
>>
>>
>>Actually, (IIRC purposely undocumented), PSP is smart enough to guess that 
>>a if code ends on a ":" you mean to start a new block.
> 
> 
> I have found documentation where this is indeed confirmed; a line ending
> in a colon (:) starts an indentation.
> 

I used indented comment trick after the for statment for a problem 
unrelated to Wouter's. I'm now in the habit of always using it.

For example, if you have a nested for loop such as the following, an 
IndentationError is raised.

<%
for title,doc_list in unit_list:
%>
   <h4>Unit <%= title %><h4>
<%
     for doc in doc_list:
%>
     <p><%= doc['url'] %>: <%= doc['title'] %></p>
<%
     # end of block
# end of block
%>

I noticed that if there was some python statement immediately after the 
first for:, the error went away. Now I always stick an indented comment 
immediately after the for statement. I also found problems when 
generating tables in the inner loop, where I was only getting a single 
closing </table> tag instead of one for each iteration of the inner loop 
(or something like that - I can't generate an example off the top of my 
head and the offending code is now gone).

I haven't commented on this before as it was a problem I had when I 
first starting using psp pages a few months ago, and I wasn't sure if it 
was a feature or a bug. :)

Regards,
Jim






















More information about the Mod_python mailing list