BTW: Take a look at the Style Guide for Python Code (PEP-8) for lots
of really helpful tips.
The empty collections (of which list is one) can be found under
Programming Recommendations of PEP-8:
http://www.python.org/dev/peps/pep-0008/#programming-recommendations
--Doug
On Wed, May 30,
didn't test it, but I spot a missing : after for x in db.test
Il giorno mercoledì 30 maggio 2012 16:08:10 UTC+2, BlueShadow ha scritto:
Hi I like to put a for-loop in a try except clause in an html file.
My problem is that the pass from the for loop terminates the try block.
{{try:}}
{{for
btw, this works perfectly as intended
trying to do 1/0
{{try:}}
{{for a in range(15):}}
{{=1/0}}
{{pass}}
{{except:}}
can't divide by 0
{{pass}}
Il giorno mercoledì 30 maggio 2012 16:15:10 UTC+2, Niphlod ha scritto:
didn't test it, but I spot a missing : after for x in db.test
I tried it too and for some weird reason it works.
The missing doublepoint you spotted is in my complete code on my server^^
what I really want to do is: diyplaying a database entry in a table.
this entry varies from no entries to about 10.
I didn't account for the no entries part but I got a
OK I did some further testing and I'm pretty stupid some basic
understanding of python would tell me that the for loop finishes without a
problem if there are no elements in it.
{{try:}}
{{print articlesformovie[0]}}
{{noarticles=0}}
{{except:}}
{{noarticles=1}}
TRTD/TDTDEs sind
you're overcomplicating a small issue
{{if articles and len(articles)0:}}
display whatever you want in a for loop
{{else:}}
display your static message
{{pass}}
Il giorno mercoledì 30 maggio 2012 16:44:22 UTC+2, BlueShadow ha scritto:
I tried it too and for some weird reason it works.
OK it obviously has nothing to do with the for loop in try except because
the for loop finishes when there are no entries in articles. But some basic
understanding of python should have told me the solution^^
thats what works if anyone is interested:
{{try:}}
{{print article[0].title}}
len(articles) is not necessary
{{if articles:}}
display whatever you want in a for loop
{{else:}}
display your static message
{{pass}}
On Wed, May 30, 2012 at 12:04 PM, Niphlod niph...@gmail.com wrote:
{{if articles and len(articles)0:}}
display whatever you want in a for loop
{{else:}}
thats even more elegant^^
Am Mittwoch, 30. Mai 2012 17:04:16 UTC+2 schrieb Niphlod:
you're overcomplicating a small issue
{{if articles and len(articles)0:}}
display whatever you want in a for loop
{{else:}}
display your static message
{{pass}}
Il giorno mercoledì 30 maggio 2012
uhm, depends if he uses lists and articles is = [], there will be a
problem.
Anyway, under some circumstances you're right.
Il giorno mercoledì 30 maggio 2012 17:11:33 UTC+2, rochacbruno ha scritto:
len(articles) is not necessary
{{if articles:}}
display whatever you want in a for
On Wednesday, May 30, 2012 11:59:13 AM UTC-4, Niphlod wrote:
uhm, depends if he uses lists and articles is = [], there will be a
problem.
What problem? An empty list evaluates to False.
Anthony
I am astonished... I missed this in almost 3 years of python development :D
I genuinely repent and knee before you, Anthony
Niphlod
Il giorno mercoledì 30 maggio 2012 18:11:32 UTC+2, Anthony ha scritto:
On Wednesday, May 30, 2012 11:59:13 AM UTC-4, Niphlod wrote:
uhm, depends if he
12 matches
Mail list logo