[mod_python] using nested blocks in psp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cloc3

    #1

    [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:
    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?

  • grahamd@dscpl.com.au

    #2
    Re: [mod_python] using nested blocks in psp

    cloc3 wrote:[color=blue]
    > 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?[/color]

    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:



    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

    Comment

    • cloc3

      #3
      Re: [mod_python] using nested blocks in psp

      grahamd@dscpl.c om.au wrote:
      See:[color=blue]
      >
      > 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.
      >[/color]

      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
      %>[color=blue]
      ><%=i%>[/color]
      </option>
      <%
      # end for
      %>
      </select>
      <input type="submit" value="acquisizione"/>
      </form>
      </html>

      Comment

      Working...