Problems with import of modules

Carl J. Van Arsdall cvanarsdall at mvista.com
Mon Jan 23 20:10:37 CET 2006


Ilias Lazaridis wrote:
> I am within a directory
>
> \doc\template\
>
> I launch script.py
>
> within this script.py, I like to import a module from the doc directory.
>
> this here does not work:
>
> form ..\..\module_name import this_one
>   
Well, if you are in linux you can do this easily by changing your 
PYTHONPATH environment variable, either by changing it explicitely or by 
editing it in your .rc files to append the /doc directory.

Although I don't know specifically where this variable might be if you 
are using windows, in either case(windows or linux), you can alter this 
from python using sys.path

import sys
sys.path.append("/doc")

Hope that helps,

-carl

> how do I go back in the directory hierarchy to import something?
>
> If this is not possible:
>
> How can I modify the python search-path from within the script, thus it 
> contains the doc directory?
>
> .
>
>   


-- 

Carl J. Van Arsdall
cvanarsdall at mvista.com
Build and Release
MontaVista Software




More information about the Python-list mailing list