PythonWin ASP performance

Jim Abrams jim at publishingresources.com
Thu Oct 18 17:51:43 EDT 2001


"maxm" <maxmcorp at worldonline.dk> wrote in
<Uxmz7.2652$5v1.259860 at news010.worldonline.dk>: 

>
>"Jim Abrams" <jim at publishingresources.com
>
>> Using Python makes life easier in so many ways I can't even begin to
>> describe them all, but some of the main ones are the object oriented
>> approach. (We've encapsulated the ASP Built-in objects with Python
>> wrappers that solve alot of VBscript ickiness, and are subclassable)
>
>I have tried Python asp, but found some ick-ines where the indenting
>messes up the clarity of the asp page.
>
>in something like:
>
><%for i in range(10):%>
>
><font size="+1"><%= i%></font><br>
>
>I have to write:
>
><%
>for i in range(10):
>    Response.Write('<font size="+1">' + i + '</font><br>')
>%>
>
>instead.
>
>In this simple example it isn't that bad, but when writing longer html,
>tables etc it sort of defeats the purpose of asp. Suddenly I get logic
>and presentation forced together.
>
>Have you got any good soultions to that?
>
>regards Max M

I agree, pretty icky. 
There's alot of approaches to solve this issue (as mentioned by other posters), but 
here's what I do, and it seems to work pretty well. (Without investing into some type of 
content vs. presentation packages)

If its a fairly simple block of HTML, put it inside a triple-quotes string and then use 
%-subs for data.

print >> _out, '''
        <tr>
          <td> </td>
          <td class="regular" width="50%%">
            <a href="email/email.asp?fmt=ppt&file=%s">Email this %s</a>
          </td>
        </tr> 
''' % (enc(path), f_type)

But you have to watch out for the regular %'s throwing you off.

Or, (and this is the method I find most useful), there is the HTMLgen package.
Simply put, it takes all the HTML tags and converts them into Python classes.
Makes life easier.


		print >> _out, TR(TD(
			TableLite(TR(
				TD(Bold(objRS.prev_link(me2), html_escape='off')),
				TD(" :: "),
				TD(Bold(objRS.next_link(me2), html_escape='off'))
			)),
			align='right',
			colspan=3
		))


You get the idea. 

><%for i in range(10):%>
><font size="+1"><%= i%></font><br>

to

><%
>for i in range(10):
>    print >> _out, Font(i, size='+1'), BR()
>%>





More information about the Python-list mailing list