473,381 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 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 1185
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
4
by: Randall Hopper | last post by:
What is the correct way to propagate exceptions from Python callbacks? When I do this: Python -> C++ -> Python Callback (example attached) an exception raised in the callback doesn't make it...
68
by: Lad | last post by:
Is anyone capable of providing Python advantages over PHP if there are any? Cheers, L.
5
by: Dan | last post by:
We have a simple site. It's a frameset with two frames a left and a right. The left frame is essentially a list of records from a database (using a server-side repeater control). When you click...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
7
by: Shadow Lynx | last post by:
I realize that his question has been asked, in many other forms, many times in this group. Even so, my tired eyes have not yet found a sufficient answer, so I've decided to "reask" it even though...
267
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.