Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: How to import custom python file in python server page (psp) ?

Reply
Thread Tools

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

 
 
Joshua Kugler
Guest
Posts: n/a
 
      03-14-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

 
Reply With Quote
 
 
 
 
Graham Dumpleton
Guest
Posts: n/a
 
      03-15-2008
On Mar 15, 6:44*am, Joshua Kugler <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Custom Controls: Import a custom namespace and use its functions within user ASP .Net 1 07-19-2007 11:03 AM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM
import .csv file into SQL Server via asp.net page Andrew J Gray ASP .Net 1 03-04-2004 11:23 AM
Question: Invoking custom file type (file associated with custom app) VB Programmer ASP .Net 1 11-03-2003 11:49 PM



Advertisments