471,853 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

python asp page keeps state across queries !?!?

I am writing asp pages in python, running on IIS 5 on Windows.

I notice that variables outside functions keep their value across
queries.
I don't know if it is normal.

Here is a little script that demonstrates it:

------------------ problem.asp ---------------------

<%@LANGUAGE=Python%>

<%

try:
if x == 0: # if x is not defined, an exception is raised here and
code goes to the except clause
pass
else:
x = x + 1 # if x exists, increment x
except:
x = 10 # if x not defined, initialize x to 10

Response.write('Hello, the value of x is ' + str(x) ) # write value
of x

%>
-----------------------------------------------------

The first time I fetch this asp page from the web browser, I get:

Hello, the value of x is 10

So far, it works.
But then, when I click on the refresh button to query the asp page
again, I get:

Hello, the value of x is 11

and then

Hello, the value of x is 12

and so on ...

Each time I reload this asp page, the x variable is incremented !!!

It seems that IIS loads this asp page like a module and keep it in
memory.
That's why all variables at the module level act as global variables
that survives to multiple queries.

To be sure, I tried a similar asp script written in VB script, and I
can see that in VBscript, variables at this same level ARE NOT kept
across different queries !!!
So, the behavior of Python asp page is different from the same page
written in VBscript.

I don't know if it is a normal thing or if it is a bug, of if I have
missed something.
Someone has an explanation ?

Aug 23 '05 #1
1 1143
nicolas_riesch enlightened us with:
I notice that variables outside functions keep their value across
queries. I don't know if it is normal.
I think it's normal.
To be sure, I tried a similar asp script written in VB script, and I
can see that in VBscript, variables at this same level ARE NOT kept
across different queries !!!
So?
Someone has an explanation ?


Speed. No need to reload the module for each query. Just don't use any
uninitialized module-scope variables. It's bad style anyway.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Aug 24 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

65 posts views Thread by Anthony_Barker | last post: by
699 posts views Thread by mike420 | last post: by
4 posts views Thread by Randall Hopper | last post: by
68 posts views Thread by Lad | last post: by
2 posts views Thread by John Lau | last post: by
7 posts views Thread by Shadow Lynx | last post: by
267 posts views Thread by Xah Lee | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.