Help! IIS and Python
sholden at holdenweb.com
Wed Feb 20 13:53:45 CET 2002
"Tim Roberts" <timr at probo.com> wrote ...
> gbreed at cix.compulink.co.uk 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 %>
> >formatter = """
> > aaa%d
> >for i in range(5):
> > Response.Write(formatter%i)
> >Why not?
> We're diving deeply into religion and philosophy here. Partly, it's just
> the principle of the thing; I assumed there was a magic method to do this
> with Python, but I'm coming to the conclusion that there is not. The
> "Response.Write" call seems extraneous to me; VBScript and JScript forms
> can omit it with the <%= trick, as if we could write this:
> for i in range(5):
> <%= formatter % i %>
> Perhaps the issue is that I don't know how the <%= form is actually
> implemented in Python/ASP. If it is just a textual substitition, where
> <%= ... %> is replaced with Response.Write(...) by simple textual
> substitution, then I understand why it is not possible.
<%= ... %> is indeed a simple macro for Response.Write(...).
The real problem is that ASP has no knowledge of indentation-sensitivity in
a language, and tends (as far as I can see) to pass blocks of code
individually to the interpreter.
It makes a lot more sense in Python to generate the whole HTML string before
emitting it with a single Response.Write() call. This anyway suits the
philosophy of modules such as HTMLGen rather better, and allows much simpler
exception handling than if you've already emitted half of your HTML!
Consulting, training, speaking: http://www.holdenweb.com/
Author, Python Web Programming: http://pydish.holdenweb.com/pwp/
"This is Python. We don't care much about theory, except where it
intersects with useful practice." Aahz Maruch on c.l.py
More information about the Python-list