473,378 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

[mod_python] using nested blocks in psp

I'm a newbie in python, and I'm fighting against nested blocks in psp.
Thats a little example with a funny behaviour:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <form>
  3. <select name="List">
  4. <!--makes a list with a loop -->
  5.  
  6. <%
  7. for i in range(50, 350, 50):
  8. if 'List' in form and int(form['List'])==i:
  9. sel="selected"
  10. else:
  11. sel="pippo"
  12. %><option value="<%=i%>" <%=sel%> ><%=i%> </option>
  13. <%
  14. %>
  15. </select>
  16. <input type="submit" value="return"/>
  17. </form>
  18. </html>
  19.  
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?

Jun 11 '06 #1
2 1646
cloc3 wrote:
I'm a newbie in python, and I'm fighting against nested blocks in psp.
Thats a little example with a funny behaviour:
Expand|Select|Wrap|Line Numbers
  1.  <html>
  2.  <form>
  3.  <select name="List">
  4.  <!--makes a list with a loop -->
  5.  <%
  6.  for i in range(50, 350, 50):
  7.   if 'List' in form and int(form['List'])==i:
  8.    sel="selected"
  9.   else:
  10.    sel="pippo"
  11.   %><option value="<%=i%>" <%=sel%> ><%=i%> </option>
  12.   <%
  13.  %>
  14.  </select>
  15.  <input type="submit" value="return"/>
  16.  </form>
  17.  </html>
  18.  
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/m...ay/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

Jun 12 '06 #2
gr*****@dscpl.com.au wrote:
See:

http://www.modpython.org/pipermail/m...ay/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:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <form>
  3. <select name="Elenco">
  4. <!--genera elenco usando un loop -->
  5.  
  6. <%
  7. for i in range(50, 350, 50):
  8. %>
  9. <option value="<%=i%>"
  10. <%
  11. if 'Elenco' in form and int(form['Elenco'])==i:
  12. %>
  13. selected
  14. <%
  15. #end if
  16. %>
  17. <%=i%>
  18. </option>
  19. <%
  20. # end for
  21. %>
  22. </select>
  23. <input type="submit" value="acquisizione"/>
  24. </form>
  25. </html>
  26.  
Jun 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mourad | last post by:
Hi all, This is an example of a nested block, however it seems Oracle doesn't like the syntax. see the error below: declare begin declare begin
0
by: Chris Birmele | last post by:
I am having difficulties maintaining table relationships when writing XML files, despite having set the relations property NESTED to TRUE. I assume therefore that something is wrong with my code. ...
1
by: Philip Townsend | last post by:
Can anybody give me some advice/feedback on using application blocks? What are the prerequisites? Do I need to install componenets, or, do I need to upgrade to the latest version of the .net...
0
by: rmacias | last post by:
I posted this in another forum but nobody has answered it: I'm creating a Windows form application in VC++ .NET 2003. I'm creating the UI is a nested namespace as follows: namespace...
3
by: kelvinweb | last post by:
Hi All, I found the Nested-Control example, but I don't understand the sources code. Anyone can send me simple logic programming source code ? Thanks alot. >From Kelvin
4
by: rach | last post by:
I just started to learn C++. I copied the following code from a data structure textbook to a ".h" file and couldn't compile it. The code contains three template interfaces. One inherits another. The...
0
by: Achim Domma | last post by:
Hi, I have an aspx file which inherits from a class "MyPageClass" which has a property "MyProperty". I want to set MyProperty in the aspx file, but code blocks are not allowed in my environment...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.