module search path

A

Ajay

hi!

I have the following directory structure.

home
user
index.cgi
common
utils.py

within index.cgi, import utils throws an errors.

I did the following

sys.path.append('../')

and then tried import common.utils and it still throws an error

it works if i give the full path name to common and add that to sys.path as
sys.path.append('/usr/hons/abrar1/lib/html/hons/um/home/common')

My question is why doesn't it work when i add the path to the parent
directory and try import common.utils?

why doesn't that work?

I dont want to rely on the full absolute path

cheers

ajay
 
A

angel

Should use sys.path.append('../common').

sys.path.append('../')
import common.utils
is error.
For the common is not a package. If you add a __init__.py in the directory
common, above code will work.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top