[python-win32] import and asp-python and iis - strange behaviour

Simon Hook simon.j.hook at jpl.nasa.gov
Tue Jun 7 05:33:37 CEST 2005


Steve,

Thanks for the quick response, everything you said works, I have a 
couple more questions. Here are a couple of scripts that illustrate how 
I implemented your suggestions.

-------file1 listing ---------------gofetch.asp
<%@ LANGUAGE = Python%>
<%
import sys
path = "d:/inetpub/wwwroot"   
sys.path.append(path)

import somefunctions
reload(somefunctions)
from somefunctions import *
%>  
<%=returnthevalue("okay it works")%>
-------------------------------------

-------file2 listing --------- somefunctions.asp
def returnthevalue(thevalue):
    return thevalue
------------------------------------

Both files go in the wwwroot directory. Now you see how bad I am at 
python, my two additonal questions are:
1) How can I avoid using an explicit path specification 
"d:/inetpub/wwwroot" I tried using os.getcwd() but that returned a 
system directory.
2) How can I avoid the 2 import calls for somefunctions. If I just use 
"import somefunctions" then I have to call the function as 
somefunctions.returnthevalue. But if I just use "from somefunctions 
import *" then reload does not work!

Thanks and great acronym BTW I had never heard that one.

Simon

Steve Holden wrote:

> Simon Hook wrote:
>
>> Hi,
>>
>> I am trying to use import in an asp python page. If I have:
>>
>> <%@ LANGUAGE = Python%>
>> <%
>> import myfile
>> %>
>>
>> Then myfile can only be found if its in the root of the python 
>> install directory, e.g.
>>
>> c:\python23
>>
>> and only if the file is called myfile.py and it contains python NOT 
>> asp code. If I have some python code and it is loaded by a webpage, 
>> if I make any changes to the code in myfile.py the changes do not 
>> come into effect unless I reboot my machine. I tried start/stop/start 
>> iis but that has no effect, I tried open/close/open and I tried the 
>> python reload() command. None of these had any effect.
>>
> Technically it will be found if the corresponding .py or .pyc is in 
> any of the directories (or other importers) on sys.path.
>
>> The only way I could get an asp-python file included was to use the 
>> asp include:
>>
>> <!--#include file="dumpform.asp"-->
>>
> This is correct.
>
>> How can I get asp to pull python code from another directory and how 
>> can I make a change and not have to reboot for the change to be 
>> invoked? Can I use import with an asp page?
>>
> Well, obviously with #include you could include a path in the 
> file="..." or virtual="..." string.
>
> You will need to ensure that sys.path contains an appropriate 
> directory to find modules you wan to import. Since you want to use 
> "import" the files must be pure Python, you can't import .ASP pages 
> (but, as you have discovered, you can include them).
>
> IIRC I did some experiments that showed me that under suitable 
> circumstances the Python interpreter will see an updated module after 
> an ASP page performs a reload() of the required module.
>
> regards
>  Steve
>
>> Many thanks Simon
>> _______________________________________________
>> Python-win32 mailing list
>> Python-win32 at python.org
>> http://mail.python.org/mailman/listinfo/python-win32
>>
>
>


More information about the Python-win32 mailing list