Help! IIS and Python

Max M maxm at mxm.dk
Thu Feb 14 04:14:54 EST 2002


Tim Roberts wrote:

 > Since we're on the subject of Python in ASP programming, how do you 
use the
 > <%=xxx%> trick with indentation?  This fails with an indentation 
error, for
 > example:
 >
 > <%
 > for i in range(5):
 > %>
 >   <%="aaa%d" % i %>

Generally I would say "don't do it". every codeblock is seen as a new 
block, so your code looks to Python like:

for i in range(5):
Response.Write("aaa%d" % i)

Perhaps this would work, I don't know:

<%
for i in range(5):
%>
<%=    "aaa%d" % i %>

You need to put all your logic before the html code, and then insert 
simple strings. This approach is also a faster for lots of content as 
joining a long list is a LOT faster than concatenating many strings.

Like:

<%
a3Nums = []
for i in range(5):
     a3Nums.append("aaa%d" % i)
a3Nums = '\n'.join(a3Nums)
%>

<%= a3Nums%>

It also makes your code much more readable. Mixing logic and 
presentation is really only a good idea for very simple pages.

regards Max M




More information about the Python-list mailing list