: : Hey, I spent some time and setup my local iis web server to facilitate the creation of ASP pages via Python.
: :
: : First off, it took me a while to integrate the concept of packages.
: :
: : I find myself having to place this code at the top of my file ...
: :
: :
: : <%
: : import sys
: :
: : # Setup Environment Path ######
: : path = "c:\development"
: :
: : try:
: : sys.path.index(path)
: :
: : except ValueError:
: : sys.path.append(path)
: :
: : ###############################
: : %>
: :
: :
: : Because A: I do not feel like setting the PYTHONPATH environment variable (because I would have to literally modify it for each web app that uses python) and
:
: Can't help you here other that to suggest some kind of .ini file with an initialization function.
:
: : B: IIS loses any information you append to the path when you restart the server process.
:
: That's because when you "import sys" you are just loading the sys module into memory. The appending of paths to sys.path is just adding another item to the in-memory list. I'm sure you knew that. Is there a way to hook the server process startup to initialize your sys.path there?
:
: : The other annoyance I came across involves some sort of mysterious caching. When I set up a module called ASP.py in a folder called cls, I can easily import it like so:
: :
: :
: : from cls import ASP
: :
: :
: : Initially calling functions from this module ran fine, but say I removed a function or modify a function; the changes do not reflect. I literally have to kill the web server process, which usually means restarting iis.
: :
: : I am wondering if this kind of behavior exists in python programs that are not strapped to a web server process? I can not help wondering if there is someway to invalidate a python module, so that the scripting engine must recompile it.
:
: That's the normal way Python handles modules. The interpreter will only load a module the first time it encounters an "import" statement. The reason is to avoid recursive reference loops. If you "import A" and A does "import B" but B does "import A" then you can see the problem. You can force the interpreter to reload a module using the reload() function:
:
: import cls.ASP as ASP
: ASP = reload(cls.ASP)
:
:
:
:
infidel
:
:
: $ select * from users where clue > 0
: no rows returned
:
:
:
-You Wrote-
"Is there a way to hook the server process startup to initialize your sys.path there?"
Well there is a file in all asp projects called global.asa. There is an Application_Start event in this file (which fires at the beginning of the web process creation), which I suppose could house the code. I'll have to see if python can hook into it. The solution I used so far, so that I am not rewritting the code, is to use an include statement ...
<!-- #include file="init.asp" -->
<%
# Other Python Code Here
%>