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

James Yu cyu021 at gmail.com
Fri Mar 14 07:15:28 EDT 2008


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,
-- 
This is a UTF-8 formatted mail
-----------------------------------------------
James C.-C.Yu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080314/2101139c/attachment.html>


More information about the Python-list mailing list