Ok, it
appears that the python script is being interpreted/executed in a parallel process at the same time as the HTML. So whereas he html still has to be processed into the buffer, the python script is ready to go.
Don't quote me on this, thats just my best guesss after tinkering with it a bit.
The solution is to put all of your output from the Python in functions and call those functions when you want your output.
Here is another comparison:
Code:
<%
Option Explicit
%>
<html>
<head><link rel="stylesheet" href="format.css"></head>
<body>
<!-- #INCLUDE FILE = "header.asp" -->
<table border="1">
<tr>
<td>
Python Row 1
</td>
<td>
<script language="Python" runat="server">
Response.Write("This gets added to the buffer immediately as the script is processed/interpreted<br>")
def print_str():
Response.Write("This gets evaluated only when it is called.")
</script>
</td>
</tr>
<tr>
<td>
Python Row 2
</td>
<td>
<%=print_str()%>
</td>
</tr>
<tr>
<td>
VBScript Row 1
</td>
<td>
<%="Just a VBScript string to show it's in the right location"%>
</td>
</tr>
</table>
<!-- #INCLUDE FILE = "footer.asp" -->
</body>
</html>
Now technically I would generally split the code a little like this.
The python will only include class and function definitions. It will be necessary to call these functions or instantiate these classes from the VBScript. For readability I would place this in either an external include file or near the top of the script:
Code:
<%
Option Explicit
%>
<script language="Python" runat="server">
def print_str():
Response.Write("This gets evaluated only when it is called.")
def incr(valu):
return valu + 1
</script>
<html>
<head><link rel="stylesheet" href="format.css"></head>
<body>
<!-- #INCLUDE FILE = "header.asp" -->
<table border="1">
<tr>
<td>
Python Row 1
</td>
<td>
5 + 1 = <%=incr(5)%>
</td>
</tr>
<tr>
<td>
Python Row 2
</td>
<td>
<%=print_str()%>
</td>
</tr>
<tr>
<td>
VBScript Row 1
</td>
<td>
<%="Just a VBScript string to show it's in the right location"%>
</td>
</tr>
</table>
<!-- #INCLUDE FILE = "footer.asp" -->
</body>
</html>
I would advise keeping all of the python code in the same set of script tags. The other reason I like it at the top is that this way the interpreter can go ahead and have time to read through all of the funtions before we have a chance to make a call. If the two processes are running independantly we don't want to take a chance of the VBScript calling a function before the Python interpreter has gotten to it yet.
Anyways, just my take on this, hope it helps,
01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website