How to import custom python file in python server page (psp) ?
Graham Dumpleton
Graham.Dumpleton at gmail.com
Sat Mar 15 02:03:17 EDT 2008
On Mar 15, 6:44 am, Joshua Kugler <jkug... at bigfoot.com> wrote:
> 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_pythonerror: "PythonHandlermod_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.
If using mod_python 3.3.1, see:
http://issues.apache.org/jira/browse/MODPYTHON-220
Graham
More information about the Python-list
mailing list