Here's what I get with your example: ------------ In [1]: list=[1,2,3,54] In [2]: for item in list: ...: print item ...: else: ...: print "no items" ...: 1 2 3 54 no items --------------- Which I don' t think is what you want.
If you want the first item, then try this: if len(list)>0: for item in list: print item else: print "no items" or if len(list)>0: print list[0] else: print "no items" For the template language (basically python, but no indent hints), you would add 'pass' anywhere unindenting is intended / would be ambiguous, e.g at the end of either of these snippets (would also be harmless to put at end of any indentation block, but not needed). Does that help? I used ipython ( http://ipython.scipy.org); you can also interactively test your apps from a shell environment in web2py (which will pre-load, and if you have ipython, take you into the ipython environment) using this form of invocation: python web2py -S myapp Hope this was helpful. Regards, Yarko On Oct 11, 4:36 pm, billf <[EMAIL PROTECTED]> wrote: > In this case I wanted the following behaviour: > > If there is at least one error message then display the first error > message else display the page message. > > I just tested the template code without the {{break}} and the {{pass}} > at the end and it passes the syntax check - I just get all the error > messages. If no-one has any solutions I suppose I can get around it > with if len(form.errors)>0 or similar. > > Bill > > On Oct 11, 10:09 pm, "Daniel Contag" <[EMAIL PROTECTED]> wrote: > > > What is the "break" for? > > > Daniel > > > On Sat, Oct 11, 2008 at 22:50, billf <[EMAIL PROTECTED]> wrote: > > > > Adding a {{pass}} at the end doesn't make any difference. > > > > On Oct 11, 9:45 pm, billf <[EMAIL PROTECTED]> wrote: > > >> New to python, I believe that the following is valid syntax: > > > >> for item in list: > > >> print item > > >> else: > > >> print 'no items in list' > > > >> When I put the following in a template I get a SyntaxError: invalid > > >> syntax error with "else:" highlighted: > > > >> {{for key,value in form.errors.items():}} > > >> <span class="error_message">{{=key}} {{=value}}</span> > > >> {{break}} > > >> {{else:}} > > >> <span class="page_message">{{=message}}</span> > > > >> What am I missing/ > > > >> Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---