[Zope-dev] Curious problem with comprehensions and PythonScripts
   
    Steve Alexander
     
    steve@cat-box.net
       
    Fri, 05 Oct 2001 17:06:19 +0100
    
    
  
Here's the situation:
I have a dtml document with a list of questions under various headings, 
formatted like this:
HEADING 1
   question1
   question2
   question3
HEADING 2
   question 4
   question 5
I have a PythonScript that gives a list of only the questions to a Page 
Template:
PythonScript called get_questions:
data=container.data_document(None, None)
# ignore blank lines
# lines with no leading space are headings
# lines with leading space are questions
return [l for l in comps.splitlines()
           if l
           if l[0] is ' ']
I'm rendering this using a page template:
<td tal:repeat="question container/get_questions">
The problem is, I'm often (always?) getting no questions rendered.
However, if I change the python script to this, it works every time.
PythonScript called get_questions:
data=container.data_document(None, None)
# ignore blank lines
# lines with no leading space are headings
# lines with leading space are questions
questions = [l for l in comps.splitlines()
                if l
                if l[0] is ' ']
return questions
Any ideas what might be happening?
I think the compiled code of the python script might be incorrect when 
directly returning the results a comprehension.
--
Steve Alexander
Software Engineer
Cat-Box limited