How to import custom python file in python server page (psp) ?

Joshua Kugler jkugler at bigfoot.com
Fri Mar 14 15:44:05 EDT 2008


James Yu wrote:

> Hi folks,
> 
> I prepared a python script for dynamically get the absolute paths of the
> files in certain folder.
> Then I tried to invoke that function from my web server in a .psp file
> like this:
> 
>       1 <html>
>       2 <head><META HTTP-EQUIV="Content-Type" CONTENT="text/html;
> charset=utf8"></head>
>       3 <title>asdfasdfasdfa</title>
>       4 <body>
>       5 <%
>       6 import glob
>       7 import os
>       8 *import Helper
> *      9
>      10 body = ''
>      11 top = 'asdfasdfasdfa'
>      12 links = {}
>      13 *Helper.GetLinks(top=top)
> *     14 *paths = Helper.GenLinkPath(links)
> *     15 body = paths
>      16 %>
>      17     <%=body%>
>      18 </body>
>      19 </html>
> 
> However, this is the error message I received when I open the page in a
> browser:
> 
>> Mod_python error: "PythonHandler mod_python.psp"
>>
>> Traceback (most recent call last):
>>
>>   File "/usr/lib/python2.5/site-packages/mod_python/apache.py", line 299,
>> in HandlerDispatch
>>     result = object(req)
>>
>>   File "/usr/lib/python2.5/site-packages/mod_python/psp.py", line 302, in
>> handler
>>     p.run()
>>
>>   File "/usr/lib/python2.5/site-packages/mod_python/psp.py", line 213, in
>> run
>>     exec code in global_scope
>>
>>   File "/var/www/.cyu021/.pic/index.psp", line 8, in
>>     import Helper
>>
>> ImportError: No module named Helper
> 
> 
> *PS. I put Helper.py and index.psp in the same dir
> *
> Thanks in advance,


What is the import path?  The current directory in PSP might not be the
directory in which the .psp file resides.  Print out sys.path before you
import your helper module to see what paths you're dealing with.

j




More information about the Python-list mailing list