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

Discussion in 'Python' started by Joshua Kugler, Mar 14, 2008.

  1. 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
     
    Joshua Kugler, Mar 14, 2008
    #1
    1. Advertising

  2. On Mar 15, 6:44 am, Joshua Kugler <> 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
     
    Graham Dumpleton, Mar 15, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lenk

    free psp host

    lenk, May 20, 2004, in forum: Python
    Replies:
    3
    Views:
    571
    Rico Huijbers
    May 21, 2004
  2. Rod Castellanos
    Replies:
    1
    Views:
    469
  3. Rod Castellanos
    Replies:
    2
    Views:
    777
    Steve Holden
    Jun 7, 2005
  4. Replies:
    1
    Views:
    475
  5. Replies:
    6
    Views:
    293
Loading...

Share This Page