python asp page keeps state across queries !?!?

nicolas_riesch nicolas.riesch at
Tue Aug 23 18:16:53 CEST 2005

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

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

Here is a little script that demonstrates it:

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



 if x == 0:    # if x is not defined, an exception is raised here and
code goes to the except clause
   x = x + 1   # if x exists, increment x
   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
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 ?

More information about the Python-list mailing list