Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Problems with import of modules

Reply
Thread Tools

Problems with import of modules

 
 
Ilias Lazaridis
Guest
Posts: n/a
 
      01-23-2006
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

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?

..

--
http://lazaridis.com
 
Reply With Quote
 
 
 
 
Farshid Lashkari
Guest
Posts: n/a
 
      01-23-2006
> How can I modify the python search-path from within the script, thus it
> contains the doc directory?


Hi,

The sys.path variable is a list of strings that contains the current
module search path. You can add your own path to this list:

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

-Farshid
 
Reply With Quote
 
 
 
 
Carl J. Van Arsdall
Guest
Posts: n/a
 
      01-23-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
http://www.velocityreviews.com/forums/(E-Mail Removed)
Build and Release
MontaVista Software

 
Reply With Quote
 
Ilias Lazaridis
Guest
Posts: n/a
 
      01-27-2006
the sys.path.append has done the work.

thanks.

..

--
http://lazaridis.com
 
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
Importing v reloading modules modules Peter Peyman Puk Python 0 03-19-2010 05:09 PM
Disabling modules using Modules/Setup Ben Weintraub Python 0 09-09-2006 12:04 AM
Importing modules from within other modules Tobiah Python 2 09-14-2003 09:18 PM
imputils - import problem modules from sys.modules Remy Cool Python 1 08-27-2003 02:25 PM



Advertisments