[Andreas Pakulat]
got a really weird problem here: Error Type: ValueError Error Value: unsupported format character '"' (0x22) at index 45
testing the following python script:
.... fmtstr += ' href="index_html?activetab=%d">%s</a></td>' %(lastelem,tabs[lastelem]) fmtstr += '<td class="headerborderwhite"><img src="%s" ' %(isrc) fmtstr += ' width="10" height="10" style="display:block;width:2em;height:2em"></td></tr></table></td>' fmtstr += '<td style="background-color:#FFFFFF;width:95%"><img src="%s"' %(spsrc)
fmtstr += ' width="3" height="3"></td></tr>'
return fmtstr
Even though Andreas is happy to have found the error, I would like to urge that Python scripts not be used to return markup at all. Instead, return a data structure to the calling page and let the page format the data - either with dhtml or zpt, it doesn't matter in this regard. Writing markup with Python has two big problems, good though Python is - 1) It is really hard to get markup right, as Andreas's example shows. Little errors are easy to make and hard to see. 2) If you want to change the look of the page, you have to rewrite your script, which is painful and prone to the same errors all over again. Using Zope templates, on the other hand, has the following strengths - 1) They are designed exactly for taking data and formatting it into markup, so it is much easier to get the markup right and to spot errors. 2) Page maintenance and changes in appearance are easy to do and do not affect the logic used in the scripts that create the data. All you have to do is have your script return the results of its computation in the form of a string, a list, a tuple, or a dictionary. The template can access all the returned data and format it. I have done it both ways - with pretty complex pages - and I can tell you that it is worth the effort to change your mental habits (which is what it takes) to find ways to just return data and not markup. Let scripts do what they do well, and let the templates do what __they__ do well.