[mod_python] using nested blocks in psp

C

cloc3

I'm a newbie in python, and I'm fighting against nested blocks in psp.
Thats a little example with a funny behaviour:
Code:
<html>
<form>
<select name="List">
<!--makes a list with a loop -->

<%
for i in range(50, 350, 50):
 if 'List' in form and int(form['List'])==i:
  sel="selected"
 else:
  sel="pippo"
 %><option value="<%=i%>" <%=sel%> ><%=i%> </option>
 <%
%>
</select>
<input type="submit" value="return"/>
</form>
</html>
In my intention, the for instruction have to run two operation:
first: the if instruction
second: to print the option tag on the html page.

Instead, the real behaviour is depending on the result of the control
in the if:
if the control is true, the option tag is not printed, and the for
instruction goes to the successive step.
if the control is false, the option is correctly printed.

I don't understand the reason of this behaviour.
Which is the right way to control the nested block instructions in psp?
 
G

grahamd

cloc3 said:
I'm a newbie in python, and I'm fighting against nested blocks in psp.
Thats a little example with a funny behaviour:
Code:
<html>
<form>
<select name="List">
<!--makes a list with a loop -->

<%
for i in range(50, 350, 50):
if 'List' in form and int(form['List'])==i:
sel="selected"
else:
sel="pippo"
%><option value="<%=i%>" <%=sel%> ><%=i%> </option>
<%
%>
</select>
<input type="submit" value="return"/>
</form>
</html>
In my intention, the for instruction have to run two operation:
first: the if instruction
second: to print the option tag on the html page.

Instead, the real behaviour is depending on the result of the control
in the if:
if the control is true, the option tag is not printed, and the for
instruction goes to the successive step.
if the control is false, the option is correctly printed.

I don't understand the reason of this behaviour.
Which is the right way to control the nested block instructions in psp?

PSP as implemented by mod_python is fussy about how many spaces are
used in indents. Use either 8 space or tab indents. If you don't want
to do that, you will need to use comment hints to help PSP understand
what level of indenting you are using. See:

http://www.modpython.org/pipermail/mod_python/2005-May/018102.html

Comment hints may still be needed in certain cases to turn off scopes
even if 8 space or tab indents are needed so it is good to understand
what they are about.

Also ask further questions on mod_python user mailing list as you will
in general get better responses there.

Graham
 
C

cloc3

http://www.modpython.org/pipermail/mod_python/2005-May/018102.html

Comment hints may still be needed in certain cases to turn off scopes
even if 8 space or tab indents are needed so it is good to understand
what they are about.

Thank you. That solves my problem.
Here the good code:
Code:
<html>
<form>
<select name="Elenco">
<!--genera elenco usando un loop -->

<%
for i in range(50, 350, 50):
%>
        <option value="<%=i%>"
<%
        if 'Elenco' in form and int(form['Elenco'])==i:
%>
                selected
<%
        #end if
%>[QUOTE]
><%=i%>[/QUOTE]
        </option>
        <%
# end for
%>
</select>
<input type="submit" value="acquisizione"/>
</form>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top