469,287 Members | 2,635 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,287 developers. It's quick & easy.

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 1071
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.